NETGEAR is aware of a growing number of phone and online scams. To learn how to stay safe click here.
Forum Discussion
mjeddajev
Apr 15, 2020Aspirant
MR1100 fails to reestablish the connection after the hang up
MR1100 - Dear netgear support, I'm having problem with connection - due to my operator restrictions, session is disconnected every hour, and solution is to switch data field OFF apply and then p...
Mexoh1To7k
Apr 16, 2020Apprentice
mjeddajev wrote:Mexoh1To7k, Could you please help me at least with the new script?
Label
Sure.
#!/usr/bin/env python3
"""
This scripts monitors the MR1100 to re-enable Data automatically.
This is useful with operators that use PPP and which systematically disconnect
users after a certain period of time.
Works with firmware 12.06.08.00
"""
import requests
import json
import time
import datetime
import sys
if len(sys.argv) < 2:
print("Usage: {} <IP> <ADMIN_PASSWORD>".format(sys.argv[0]))
sys.exit(1)
ip = sys.argv[1]
pwd = sys.argv[2]
timeout = 2
url_base = "http://{}".format(ip)
url_session = "{}/sess_cd_tmp".format(url_base)
url_js_token = "{}/api/model.json".format(url_base)
url_config = "{}/Forms/config".format(url_base)
url_json = "{}/api/model.json".format(url_base)
url_json_success = "{}/success.json".format(url_base)
url_success = "{}/index.html".format(url_base)
def login(r):
try:
api = r.get(url_js_token, timeout=timeout).text
except:
print("Failed to connect to router")
return
try:
api = json.loads(api)
global token
token = api['session']['secToken']
except:
print("Failed to fetch authentification token")
return
data = {
'token': token,
'err_redirect': '/index.html?loginfailed',
'ok_redirect': '/index.html',
'session.password': pwd,
}
try:
redirect_url = r.post(url_config, data=data, timeout=timeout).url
if redirect_url == url_success:
return True
else:
print("Failed to authenticate, incorrect password?")
return
except:
print("Router failed to respond to authentication challenge")
return
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):
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',
}
try:
push = r.post(url_config, data=disconnect, timeout=timeout)
if push.url != url_json_success:
print("Failed to disconnect data")
except:
print("Invalid answer from router")
return
try:
push = r.post(url_config, data=connect, timeout=timeout)
if push.url != url_json_success:
print("Failed to reconnect data")
return
except:
print("Invalid answer from router")
def main(dry_run=None):
data_status = None
r = requests.Session()
login_status = login(r)
if login_status != True:
return
else:
data_status = get_status(r)
if dry_run is True:
return True
if data_status != "Connected":
print("Data appears to be disconnected, reconnecting..")
reconnect(r)
nb_tries = 0
while data_status != "Connected" or nb_tries < 3:
data_status = get_status(r)
time.sleep(1)
nb_tries+=1
if data_status == "Connected":
timestamp = datetime.datetime.now()
timestamp = timestamp.strftime("%Y-%m-%d %H:%M:%S")
print("Reconnection successful {}".format(timestamp))
else:
print("Data is still offline, this should not happen")
if __name__ == '__main__':
try:
dry_run = main(dry_run=True)
if dry_run is None:
sys.exit(1)
else:
print("Connection to router successful. Monitoring disconnections")
while True:
main()
time.sleep(2)
except KeyboardInterrupt:
sys.exit(0)
For the script to run you only need the requests module which you'd usually install with pip in this fashion:
pip3 install requests
I will make a new version of the script to remove this dependency.
mjeddajev
Apr 16, 2020Aspirant
Thanks a lot! Great job! Works like magic from the very first execution! You saved my quarantine and my peace of mind!
No need to bother yourself with rewriting script to avoid requests usage - anyone who managed to install and run python script will manage to install requests too.
Now I will keep my finger crossed for Netgear firmware with this issue fixed.