Skip to content

Instantly share code, notes, and snippets.

@rajeebbanstola
Created July 16, 2017 17:21
Show Gist options
  • Save rajeebbanstola/941a42d4bd3d6c8be22cf9a23d75298a to your computer and use it in GitHub Desktop.
Save rajeebbanstola/941a42d4bd3d6c8be22cf9a23d75298a to your computer and use it in GitHub Desktop.
Reboot Router when internet stops working. P.S.: I only know a animal by the name of Python.
import requests
from requests.auth import HTTPBasicAuth
import httplib
def have_internet():
conn = httplib.HTTPConnection("www.google.com", timeout=5)
try:
conn.request("HEAD", "/")
conn.close()
return True
except:
conn.close()
return False
if have_internet() :
print "Internet is working"
else:
session = requests.Session()
login_data={'username':'admin','password':'admin12345','submit.htm?login.htm':'Send'}
session.post('http://192.168.10.1/login.cgi', data=login_data)
reboot_data = {'reboot':'Reboot','submit.htm?reboot.htm':'Send'}
reboot = session.post('http://192.168.10.1/form2Reboot.cgi', data=reboot_data)
reboot.headers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment