Skip to content

Instantly share code, notes, and snippets.

@ma4a
Created July 23, 2012 22:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ma4a/3166580 to your computer and use it in GitHub Desktop.
Save ma4a/3166580 to your computer and use it in GitHub Desktop.
Python script for Vodafone Easybox 802 - get current internet speed
import re, string, sys, time, urllib
"""
*tested with Easybox 802 Firmware 20.02.233
"""
#SETTINGS *** only change values in this area
routerIP = "192.168.0.1" #address of router
routerUser = "root" #default: root
routerPW = "secret123" #pass for login
totalDownloadInKbps = 6910 #max download (value from website)
totalUploadInKbps = 731 #max upload
percentOk = 90 #min percentage of total rate to be 'okay'
#end of SETTINGS *** only change values in the area above
def startSession():
loginForm=urllib.urlencode({"user" : routerUser, "pws" : routerPW})
loginData = urllib.urlopen("http://" + routerIP + "/cgi-bin/login.exe", loginForm)
loginData.close()
def getDatapage():
jsVars = {}
getData = urllib.urlopen("http://" + routerIP + "/status_main.stm")
for z in getData:
findIt = re.match(r"^var[ ]*(.*)\=(.*);", string.replace(z, "\"", ""))
if findIt != None:
#print findIt.group(1), "--->", findIt.group(2)
jsVars[findIt.group(1)]=findIt.group(2)
getData.close()
return jsVars
def getData(varName):
startSession()
jsVars = {}
getData = urllib.urlopen("http://" + routerIP + "/status_main.stm")
for z in getData:
findIt = re.match(r"^var[ ]*(.*)\=(.*);", string.replace(z, "\"", ""))
if findIt != None:
#print findIt.group(1), "--->", findIt.group(2)
jsVars[findIt.group(1)]=findIt.group(2)
getData.close()
endSession()
return jsVars[varName]
def endSession():
logoutData = urllib.urlopen("http://" + routerIP + "/cgi-bin/logout.exe")
logoutData.close()
def restartRouter():
startSession()
rsData = urllib.urlopen("http://" + routerIP + "/cgi-bin/restart.exe")
print "Restart initiated. Wait a few seconds..."
rsData.close()
endSession()
def query_yes_no(question, default="yes"):
"""Ask a yes/no question via raw_input() and return their answer.
"question" is a string that is presented to the user.
"default" is the presumed answer if the user just hits <Enter>.
It must be "yes" (the default), "no" or None (meaning
an answer is required of the user).
The "answer" return value is one of "yes" or "no".
"""
valid = {"yes":True, "y":True, "ye":True,
"no":False, "n":False}
if default == None:
prompt = " [y/n] "
elif default == "yes":
prompt = " [Y/n] "
elif default == "no":
prompt = " [y/N] "
else:
raise ValueError("invalid default answer: '%s'" % default)
while True:
sys.stdout.write(question + prompt)
choice = raw_input().lower()
if default is not None and choice == '':
return valid[default]
elif choice in valid:
return valid[choice]
else:
sys.stdout.write("Please respond with 'yes' or 'no' "\
"(or 'y' or 'n').\n")
startSession()
vars = getDatapage()
endSession()
if len(vars) > 0:
print "***", vars["product_name"], "***\n"
print "Download:", vars["download_rate"], "(max. "+str(totalDownloadInKbps)+")"
print "Upload:", vars["upload_rate"], "(max. "+str(totalUploadInKbps)+")\n"
if ((int(vars["download_rate"]) >= totalDownloadInKbps*percentOk/100) and (int(vars["upload_rate"]) >= totalUploadInKbps*percentOk/100)):
print "Everything works great..."
else:
print "Oh oh. Internet seems too slow!"
if query_yes_no("Do you want to restart the router to get a better speed?", default="no"):
print "Restarting Router... "
IPold = vars["wan_ip"]
print "IP before:", IPold
restartRouter()
time.sleep(70)
IPnew = getData("wan_ip")
print "IP after:", IPnew
if IPold <> IPnew:
print "Looks good now..."
else:
print "Mhh... not the desired value. Try again or wait a few more seconds..."
else:
print "Error collecting JavaScript vars..."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment