Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re
- import getpass
- import sys
- import telnetlib
- import time, threading
- from subprocess import check_output
- def routerTelnet():
- print (time.ctime())
- speedText = check_output(['C:\Program Files\cFosSpeed\spd.exe', 'speed']).decode('utf-8')
- regex = re.compile(r'txspeed=(\d+|\d+\.\d+)[K|\s]\s+fixed=', re.MULTILINE)
- matches = [m.groups() for m in regex.finditer(speedText)]
- print (speedText)
- print (matches)
- upspeed = float(matches[0][0])
- if upspeed > 1024:
- upspeed /= 1024;
- print ("upload speed = ", upspeed)
- if upspeed < 20.0 and upspeed > 4.0:
- print("speed dropped: ")
- HOST = "192.168.1.1"
- user = 'admin'
- password = '?password?'
- tn = telnetlib.Telnet()
- tn.open(HOST, 23)
- tn.read_until( 'Username: '.encode('ascii'))
- tn.write((user + "\r\n").encode('ascii'))
- tn.read_until( 'Password: '.encode('ascii'))
- tn.write((password + "\r\n").encode('ascii') )
- print("restarting the router")
- tn.write( ('reboot' + '\r\n').encode('ascii'))
- print(tn.read_all())
- else:
- print("speed is normal")
- threading.Timer(1 * 60 * 15, routerTelnet).start()
- routerTelnet()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement