微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

路由器连接失败

如何解决路由器连接失败

我已经在 pip 中安装了 routeros,但仍然显示错误。 从我的前辈那里得到了这个代码。 我正在尝试收集网络中的连接状态。

import routeros_api
import json
import datetime
import sys

#make a connection to MikorTik Router
connection = routeros_api.RouterOsApiPool('IP',username='name',password='mypassword',plaintext_login=True,port=8888)
api = connection.get_api()

#command to retreive data
list_queue = api.get_resource('/queue/tree')
QueueItems = list_queue.get() #get output from Mikrotik command
Uptime = api.get_resource('system/resource')
UptimeItems = Uptime.get() #get output form Mikoritk command
SystemClock = api.get_resource('/system/clock')
SystemClockItems = SystemClock.get()

#list System Clock items
for item in SystemClockItems:
        time = item['time']
        date = item['date']

#list uptime of MikorTik router
for item in UptimeItems:
    range = item["uptime"] #stores uptime from mikroitk in 2d3h30m format
    
CurrentUpTime = range[0] # stores only the 1st digit of Mikortik uptime output whihc corresponds to DAYS

data = {}           #create dictionary to store 
data["time"] = []   #create list in the dictionary to store time key value pair
data["users"] = []  #create lsit in the dictionary to stor users key value pair

data2 = {}           #create dictionary to store new data after mikoritk restarts
data2["time"] = []   #create list in the dictionary to store time key value pair
data2["users"] = []  #create lsit in the dictionary to stor users key value pair

#open output file to compare Uptime of Mirkotik
with open('output.txt','r') as file:
    data = json.load(file)
    for p in data["time"]:
        PrevIoUsUpTime = p['currentuptime']        
#Take data from Queue and store it in file output.txt in json format


data = {}  #create dictionary to store 
data["system"] = []  #create list in the dictionary to store time key value pair
data["users"] = []  #create lsit in the dictionary to stor users key value pair
with open('output.txt','w') as f:  # open file where to dump data
    
    data['system'].append({"currentuptime" : CurrentUpTime}) #add current uptime of Mikrotik
    data['system'].append({"time" : time}) 
    data['system'].append({"date" : date})
    for item in QueueItems:                                  #loop through mikoritk ouptu for each user
        if item["parent"] == "Sharing policy":             #only show user downloads data under this tree
            GigaBytes = int(item["bytes"]) / 1073741824      #convert data to Gigbaytes
            temp_dict = { "name" : item["name"],"Gigabytes" : GigaBytes}
            data['users'].append(temp_dict)
    json.dump(data,f,indent=6)                               #dump data into file opened above in json format 

我得到的输出

import routeros_api

ModuleNotFoundError: 没有名为“routeros_api”的模块

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。