NETGEAR is aware of a growing number of phone and online scams. To learn how to stay safe click here.
Forum Discussion
Georgiana
Jan 04, 2019Follower
Netgear Nighthawk M1 - data connection problem
MR1100 - Dear netgear support, I am writing because you are the last chance to fix the product otherwise I will have to throw it away. I have several problems, but the most important is that the devi...
nokiahelp
Apr 23, 2019Tutor
Mexoh1To7k hello, I'm interested in the script too :D
Mexoh1To7k
May 05, 2019Apprentice
Hi,
Sorry for that long delay. I have attached the script.
Just adjust the 'ip' and 'pwd' variables to reflect your MR1100 and keep the script running.
This is a python 3 script.
#!/usr/bin/python3
import requests
import json
import time
import datetime
ip = "192.168.1.1"
pwd = "admin"
url_session = "http://{}/sess_cd_tmp".format(ip)
url_js_token = "http://{}/js/NetgearStrings.js".format(ip)
url_config = "http://{}/Forms/config".format(ip)
url_json = "http://{}/api/model.json".format(ip)
url_json_success = "http://{}/success.json".format(ip)
url_success = "http://{}/index.html".format(ip)
timeout = 3
first_run = True
def router_reachable(r):
global first_run
try:
s = r.get(url_session, timeout=timeout)
first_run = False
if s.status_code != 200:
raise ValueError("Wrong status code")
print("Connect OK.")
except:
print("MR1100 unreachable. Wrong IP?")
exit(1)
def login(r):
try:
r.get(url_session, timeout=timeout)
except:
print("Connection failed. Wrong IP?")
time.sleep(2)
try:
js = r.get(url_js_token, timeout=timeout).text
global token
token = js.splitlines()[11].split()[1].strip('"')
data = {
'token': token,
'err_redirect': '/index.html?loginfailed',
'ok_redirect': '/index.html',
'session.password': pwd,
}
except:
print("Token computation failed.")
login_success = False
try:
redirect_url = r.post(url_config, data=data, timeout=timeout).url
if redirect_url == url_success:
login_success = True
else:
print("Failed to authenticate, incorrect password?")
exit(1)
return login_success
except:
print("Connection failed.")
def get_status(r):
try:
json_model = json.loads(r.get(url_json, timeout=10).text)
status = json_model['wwan']['connection']
return status
except:
print("Cannot retrieve connection status.")
def reconnect(r):
try:
disconnect = {
'token': token,
'err_redirect': '/error.json',
'ok_redirect': '/success.json',
'wwan.autoconnect': 'Never',
}
connect = {
'token': token,
'err_redirect': '/error.json',
'ok_redirect': '/success.json',
'wwan.autoconnect': 'HomeNetwork',
}
push = r.post(url_config, data=disconnect, timeout=timeout)
push2 = r.post(url_config, data=connect, timeout=timeout)
if push.url != url_json_success:
print("Failed to disconnect.")
elif push2.url != url_json_success:
print("Failed to reconnect.")
except:
print("Connection failed.")
def main():
r = requests.Session()
if first_run:
router_reachable(r)
login(r)
status = get_status(r)
if status != "Connected":
reconnected = False
while not reconnected:
reconnect(r)
time.sleep(5)
status = get_status(r)
if status == "Connected":
timestamp = datetime.datetime.now()
s = "Reconnect successful {}".format(timestamp)
reconnected = True
print(s)
time.sleep(2)
if __name__ == '__main__':
while True:
try:
main()
except KeyboardInterrupt:
exit(0)
except SystemExit as e:
exit(1)
except:
time.sleep(2)
main()- nokiahelpMay 05, 2019Tutor
Mexoh1To7k Many thanks !
Maybe a stupid question but the script needs to run on a PC connected to the router, right ?
Is it possible to execute the script on an android device (like a tablet) ?
Thanks again :)
- Mexoh1To7kMay 05, 2019Apprentice
Yes, the machine on which you run the script must have access to the web interface of the MR1100.
Android generally doesn't ship with Python, but there's a terminal emulator called Termux that seems to include it. Feedback appreciated.
- nokiahelpMay 05, 2019Tutor
OK, thank you
I've installed Termux but there is a problem when importing requests (and maybe the two others). Please see the screenshoot in attachment