Python监控腾达路由器下设备网速

Python监控腾达路由器下设备网速,第1张

Python监控腾达路由器下设备网速

办公室里装了一个监控,摸鱼什么的很不方便,偶然发现办公室里的监控摄像头没人登录看的时候网速为0,只有在有人看的时候网速会变化,于是写了一个程序爬取摄像头设备的网速.

办公室用的是腾达的路由器,管理网址是腾达无线路由器

爬数据这一块网上有现成的,Flask 和 requests 搭建一个简单的API服务! - 知乎 (zhihu.com),直接CV大法,然后自己改了下,加了个网速变化检测,代码如下,看不懂的可以在地下评论问. (d:下载速度  u:上传速度)

import time
import easygui    #懒得写tkinter,直接用easygui,该库须pip安装
import requests

import json
module = [
    "wifiBasicCfg",
    "wifiAdvCfg",
    "wifiPower",
    "wifiWPS",
    "wifiGuest",
    "wifiBeamforming",
    "loginAuth",
    "wanAdvCfg",
    "lanCfg",
    "softWare",
    "wifiRelay",
    "sysTime",
    "remoteWeb",
    "isWifiClients",
    "systemInfo",
    "hasNewSoftVersion",
    "internetStatus",
    "deviceStatistics",
    "parentCtrlList",
    "parentAccessCtrl",
    "wanBasicCfg",
    "localhost",
    "onlineList",
    "macFilter",
    "guestList",
    "staticIPList",
    "IPTV",
    "portList",
    "ddns",
    "dmz",
    "upnp",
    "ping"
]


class Wifi():
    """获取连接本WiFi的其他设备信息"""

    def __init__(self, IP='192.168.0.1'):
        self.IP = IP
        self.data = self.req()

    def req(self):
        """获取WiFi数据"""
        req = requests.session()
        module_args = ",".join(module)
        url = f'http://{self.IP}/goform/getStatus?&modules={module_args}'
        try:
            req = req.get(url).json()
            '''with open("wifi.json", 'r') as data:
                req = json.loads(data.read())'''
            self.status = True
        except:
            self.status = False
        return req



u=0
d=0
wifidata=Wifi().req()
b=wifidata['onlineList']
for i in range(0, len(b)):
    # print(b[i])
    print(str(i)+'  R: '+b[i]['qosListRemark']+"  H: "+b[i]['qosListHostname'])
ch=int(input("choose(num): "))    #选择设备
lr=b[ch]['qosListRemark']
lh=b[ch]['qosListHostname']
print(lr,lh)
easygui.msgbox(str(lr+' '+lh))

st=time.time()
last=st
while True:
    wifidata=Wifi().req()
    b=wifidata['onlineList']

    now = str(last - st)
    for i in range(0,len(b)):
        #print(b[i])
        if b[i]['qosListRemark']==lr or b[i]['qosListHostname']==lh:
            #print(b[i])
            #print(i)
            d=float(b[i]['qosListDownSpeed'])    #下载速度
            u=float(b[i]['qosListUpSpeed'])     #上传速度
            print("r"+"D "+str(b[i]['qosListDownSpeed'])+"   U "+str(b[i]['qosListUpSpeed'])+' RUN'+now+'  load '+str(time.time()-last),end='')

    if u>0 or d>0:    #检测
        easygui.msgbox('WARNING: '+"D "+str(b[i]['qosListDownSpeed'])+"   U "+str(b[i]['qosListUpSpeed']))


    last = time.time()


运行:

 

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5679593.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存