Advertisement
Guest User

Untitled

a guest
May 23rd, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. import re
  2. import getpass
  3. import sys
  4. import telnetlib
  5. import time, threading
  6. from subprocess import check_output
  7.  
  8. def routerTelnet():
  9. print (time.ctime())
  10.  
  11. speedText = check_output(['C:\Program Files\cFosSpeed\spd.exe', 'speed']).decode('utf-8')
  12.  
  13. regex = re.compile(r'txspeed=(\d+|\d+\.\d+)[K|\s]\s+fixed=', re.MULTILINE)
  14.  
  15. matches = [m.groups() for m in regex.finditer(speedText)]
  16.  
  17. print (speedText)
  18. print (matches)
  19.  
  20. upspeed = float(matches[0][0])
  21.  
  22. if upspeed > 1024:
  23. upspeed /= 1024;
  24.  
  25. print ("upload speed = ", upspeed)
  26.  
  27. if upspeed < 20.0 and upspeed > 4.0:
  28. print("speed dropped: ")
  29.  
  30. HOST = "192.168.1.1"
  31. user = 'admin'
  32. password = '?password?'
  33.  
  34. tn = telnetlib.Telnet()
  35. tn.open(HOST, 23)
  36. tn.read_until( 'Username: '.encode('ascii'))
  37. tn.write((user + "\r\n").encode('ascii'))
  38.  
  39. tn.read_until( 'Password: '.encode('ascii'))
  40. tn.write((password + "\r\n").encode('ascii') )
  41.  
  42. print("restarting the router")
  43.  
  44. tn.write( ('reboot' + '\r\n').encode('ascii'))
  45.  
  46. print(tn.read_all())
  47. else:
  48. print("speed is normal")
  49.  
  50. threading.Timer(1 * 60 * 15, routerTelnet).start()
  51.  
  52. routerTelnet()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement