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 put data ON and apply in cellular settings. Other devices with the same operator managing such disconnection without any problems.
Exactly the same issue as was described https://community.netgear.com/t5/Mobile-Routers-Hotspots-Modems/Netgear-Nighthawk-M1-data-connection-problem/td-p/1685333
Unfortunatelly, that discusssion is closed, so I have to create the new one. Solution with pythion script is not applicable because script fails to pass authentification ("Failed to authenticate, incorrect password?"), probably because my firmware is NTG9X50C_12.06.11.00 and not the one script was created to (NTG9X50C_12.06.02.00)
Mexoh1To7k, Could you please help me at least with the new script?
Label
7 Replies
- Mexoh1To7kApprentice
mjeddajev wrote:Mexoh1To7k, Could you please help me at least with the new script?
LabelSure.
#!/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.
- mjeddajevAspirant
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.
- maroc84Aspirant
Thank you for this script. I used it but my mr1100 was still disconnected. Probably because I run it
with
python script.py ip password &
?
Anyway. Would you mind if I use parts of your code to build a script that periodically reconnects after 24 h to avoid the forced disconnecting of my provider in the first place. I never wrote other than normal bash script so this would be a more as solid base to do so.
- Mexoh1To7kApprentice
maroc84What does the script says when you run it?
Also, you may need to check your firmware's version and use the appropriate script.
The script monitors for disconnections to reestablish data regardless of the periodicity of the disconnections. Whether they happen every 6, 12 or 24 hours, the script will re-anable data within seconds.
Yes, you are free to do what you want with the script.
- maroc84Aspirant
Mexoh1To7kI tried several times to reply again but my posts disappeared. I don't know why.
So I try again without code.
My Model is from europ (1100-100EUS)
FW: 12.06.11.00
I ran your script again the last two days over night without success. When I manually uncheck mobile data in the mr1100 while running the script it does its job but not when the connection gets cut by the provider over night.
That night it was disconnected an your script didn't work.
I manually killed the script, started it again that morning (about 5:30 am). As far as I can tell it stucks on "Data appears to be disconnected, reconnecting..". till my ssh connection was timed out.
I have a external server monitoring my connection status. So I can tell that my router was offline from 5:23 to 8:24 am.
Could you provide a solution to get a working logfile from your script?
I tried with
python script.py IP PASS >> logfile
But this did't work and I have no clue how to use the logging module in your script ;)
- Mexoh1To7kApprentice
maroc84Is the Data button checked or unchecked when you are disconnected?
The script appears to correctly detect that Data has been disabled. Perhaps it fails to re-enable it.
- maroc84Aspirant
Sorry for my late reply.
So your script was working fine. I found out I ran my MR1100 in bridge-mode (IP-Passthrough) what wasn't working correctly therefor I could reach the IP of it without problems. This may be the reason the script couldn't restart the connection if lost.
After setting the MR1100 to normal router-mode and my router behind it as a IP-client it worked flawless.
So other news. Yesterday I got a firmware update to 12.06.12.00 and had no change log so I disabled your script for testing purposes and YEAY - without your script as active service on my raspberry py 4 the connection was rebuild after provider-site disconnection!
hopefully this wasn't just some strange mistake ;)