in reply to Detecting when my ISP changes my IP
The script runs every five minutes. In the event that eth1 has been dropped, it restarts network, then on the next go 'round restarts nptd if the IP has changed. Maybe there will be something of value in there for you.#!/usr/bin/perl use strict; my $lastip; if (open IP, '</home/phil/usr/cron/lastip.dat') { $lastip = <IP>; chomp $lastip; close IP } else { print "**keepalive.pl** File 'lastip.dat' cannot be opened to read +: $!" } if (`netstat -i` =~ /eth1.*?inet addr:(\d+\.\d+\.\d+\.\d+)/s) { if ($1 ne $lastip) { print "**keepalive.pl**\n\n".`/etc/init.d/ntpd restart`; if (open IP, '>/home/phil/usr/cron/lastip.dat') { print IP "$1\n"; close IP } else { print "**keepalive.pl** File 'lastip.dat' cannot be opened + to write: $!" } } } else { print "**keepalive.pl**\n\n".`/etc/init.d/network restart` }
There's also a companion cron script (ddclient, a free perl script I downloaded) that keeps separate tabs on my IP address and keeps my dyndns entry up-to-date. ddclient uses a remote IP echoing server to obtain the address -- but, of course, fails when eth1 is killed.
|
|---|