The ZyXEL NBG4115 is a small, cheap 3G router that can be used to build a wireless network where there is no access point available. You plug one of those 3G dongles into it, enter the PIN number, and you have a local access point in the middle of nowhere. At Neurobat we use these devices whenever we require internet access to a test site that cannot have internet access otherwise. One problem we ran into very early on, however, is that the 3G connection provided by Swisscom tends to be, to put it charitably, flaky. Indeed, we have never had a single connection remain alive for more than a week. We have spoken with their tech support, upgraded the firmware on the 3G dongles, all to no avail. As a final solution we decided to write scripts on the local netbooks that would regularly (say, once every three hours) reset the connection through the router’s administrative web interface. Only problem was that none of the “easy” screen-scraping tools out there (wget
, Python’s urllib
, etc) was Javascript-capable-–|which is something the web interface would detect, and refuse any client that was not Javascript-enabled. In the end we decided to install a Selenium server on each netbook, and wrote a Python script that would talk to the Selenium server and reset the router. If this can help anyone, here is the (simple) Python script to reset a ZyXEL 3G router through Selenium, assuming a Selenium server has been started and is listening on port 4444:
#!/usr/bin/env python
from selenium import webdriver
browser = webdriver.Remote("http://localhost:4444/wd/hub", webdriver.DesiredCapabilities.HTMLUNIT)
# Login
browser.get("http://192.168.1.1")
pass_field = browser.find_element_by_name("textfield")
pass_field.clear()
pass_field.send_keys("*****")
pass_field.submit()
# Click restart
try:
browser.get("http://192.168.1.1/mtenrestart.html")
except:
pass
button = browser.find_element_by_name('apply')
button.click()
And here is the Bash script that controls it all, and that we call from a cronjob:
#!/bin/bash
TOOLS=`dirname $0`
# Start Selenium server
java -jar $TOOLS/selenium-server-standalone.jar > /dev/null 2>&1 &
SELENIUM=$!
sleep 10
# Reset router
$TOOLS/restart_zyxel.py
# Kill Selenium
kill $SELENIUM
If you find this to be of use I’d be happy to hear from you in the comments below.
5 thoughts on “Selenium script to reset a ZyXEL NBG4115 4G Router”
Comments are closed.
I do not know if it’s just me or if perhaps everyone else encountering issues with your blog. It seems like some of the text on your content are running off the screen. Can somebody else please comment and let me know if this is happening to them too? This may be a issue with my browser because I’ve had this happen before.
Appreciate it
Wow, this is really great staff. I am experiencing the same 3G reconnect issues and thought to give your path a try. I deployed Selenium on my system according to this manual < http://www.danstraw.com/installing-selenium-server-2-as-a-service-on-ubuntu/2010/09/23/ > and modified your scripts to my needs in regards to IPs and PW. However, when I fire the script, to following issue poped up: pass button = browser.find_element_by_name(‘apply’)
^
SyntaxError: invalid syntax
Any advice?
Thanks
Andreas
@Andreas is quite right; there was a syntax error in my code snippet, probably due to a rogue copy/paste operation. I’ve fixed that now.
Thanks David, that did the trick. Reload for the Zyxel is now working. Lets hope the best, that this will fix my 3G connection issues as well. Andreas
Hi,
I have no idea of Python, Selenium and/or ‘how do’: I just have a NBG4115 3G router and I would like to upgrade to 4G.
My question is:
is this script good for me too ?
if yes, how can I put the script into the router ?
and ‘what other’ must I know ?
somebody speaks italian or german ?
Thanks in advance
Bye
Pino