checkwan (for USR9106)
On a remote server I'm using an ADSL modem-router-gateway U.S.Robotics USR9106 (USR139106) which holds the internet connection for the server itself. In order to easy maintain the PC and the applications from remote, I also have set up an account with dyndns which keeps the dynamic IP always linked to a simbolic url. At the expiration of ISP's DCHP lease time, the IP is renewed and changed, so I have installed ddclient to keep the dynamic DNS updated.
It could happen that sometimes the dyndns.org server is not available, or some updating process didn't perform correctly. In such a case I will never get my PC from remote because I am not able to know the new IP assigned from my ISP. Few times I also had another problem: when ISP changes the IP, the router hangs and its WAN state flag goes down.
I absolutely need to get the server from remote, as it is running some critical situation, so I should remove each possible hang or failure from the system, like a router "down" state.
To avoid such inconvenient situations, I have written a Perl script named "checkwan".
How does it work
The program can run in two modes: stand-alone or looping in a cronjob. Let's have a look at the help screen:
fabio@Rospo:~$ ./checkwan -h checkwan v. 1.0.0 - Fabio Marzocca 2004 - thesaltydog@gmail.com
usage: checkwan [OPTIONS] OPTIONS: -r, --reboot the script will check for UP router status. If not, the router will be reboot-ed. This mode is intended to be used in a cronjob;
-s, --show the router WAN details will be printed on STDOUT;
-i, --ipaddr also for cronjob: in this mode the script will check for changing in WAN IP address. If changed, it will e-mail it to [emailaddress], if provided.
-e, --email =<emailaddress> this is the email address where the user will be notified of an IP change. Useful only together with -i option.
-h, --help will print this screen;
As a standalone application, checkwan shows all the relevant WAN data. Here it is an example:
fabio@Rospo:~$ ./checkwan -s
checkwan v. 1.0.0 - Fabio Marzocca 2004 - thesaltydog@gmail.com VCC= 0.8.35 Category= UBR Serv. Name= pppoa_8_35 Interf. Name= ppp41 Protocol= PPPoA State= Enable Status= Up IP= 82.51.158.190
As a cron job, the script can be run to check for an IP address change (-i -e= fabio@mydomain.com) or to check for needing of reboot (-r) or both (-r -i -e=fabio@mydomain.com) In ipaddress mode, checkwan periodically connects to the USR9106 thru Telnet. It authenticates to the router and reads the current IP which the router is assigned to. If this IP is NOT the same as detected at the previous script run, checkwan immediately send me an e-mail message with the new IP address.
In this way, I am always able to reach the remote server. If ddclient fails, I have the current IP from my mail so I can connect to the PC thru ssh, restart ddclient or simply manually update my IP on dyndns.org web site.
In reboot mode, if the WAN status flag is not 'Up', checkwan will reboot the router, which will go back online after the rebooting process.
Installation
Just put the script in a path directory (i.e.: /usr/local/bin) and make it executable:
chmod a+x checkwan
With a common text editor, you first need to setup 5 variables in the script (the first 5 ones):
$userid and $ password ------> your personal access data to the USR9106.
$VPI and $VCI-----> your ISP VPI and VCI connection data.
$routerIP -------> The IP of the router in your LAN (i.e. 192.168.1.1)
Use
Just add the script as a cron job to /etc/crontab.Example:
5 * * * * root </path>/checkwan -r -i -e=george@whouse.gov
In the example the script runs each hour (at minute 5), but you can tune this value as you need. In this case it means that I will not stay more than an hour without knowing the right address of my server.
Download
Feedback
If you need more information, or if you simply need to contact me, my e-mail address is