Detecting an IP address change

dvl@

Developer
My home network uses DHCP to get an IP address from my ISP. I want to start keeping track of how often this IP address changes. Why? Because I can.

Or can I?

I have recently found dhclient-enter-hooks and I'm thinking about using that. But it seems I'll have to write my own scripts, maintain stats, etc. Does something similar already exist? I am now using no-ip.com and I would be willing to switch to a new DYN-DNS service which keeps a history of IP address changes.
 
What exactly do you mean with "..., maintain stats, ...". Is this more than logging the changes into a file e.g. /var/log/ip-changes.log?

If you would require only some sort of a log file, then you could use the script that I recently announced in the forum for updating a DYN-DNS service by the way of dhclient-exit-hooks. You would simply replace the call to curl in said script with a logging command line, something like:

Code:
echo "`date`  dhclient-exit-hook: $currentIP was switched to $newIP." >> /var/log/ip-changes.log
 
Yes, I wanted more than just logging changes, but that would be a good start. I think the ideal solution would be a web page, showing a date and an IP address.

I will investigate your script. I am also testing ddclient right now and getting SSL errors. I suspect your curl solution is much better.
 
dvl@ said:
Yes, I wanted more than just logging changes, but that would be a good start. I think the ideal solution would be a web page, showing a date and an IP address.
You could write the information (including the date) to a file and show that file on a web site. You could also upload the data to an external site. The web site may need a bit of logic to nicely present the data but that shouldn't be too hard to make.
 
FYI, I was able to get ddclient to work, but only with a local modification:

Code:
 $ diff -u /usr/local/sbin/ddclient~ /usr/local/sbin/ddclient.mine
--- /usr/local/sbin/ddclient~   2013-09-04 19:20:17.000000000 +0000
+++ /usr/local/sbin/ddclient.mine       2013-09-04 21:26:58.148511520 +0000
@@ -1863,6 +1863,7 @@
             Proto => 'tcp',
             MultiHomed => 1,
             Timeout => opt('timeout'),
+            SSL_ca_file => '/usr/local/share/certs/ca-root-nss.crt',
         );
            defined $sd or warning("cannot connect to $peer:$port socket: $@ " . IO::Socket::SSL::errstr());
     } else {

That said, I will be using the solution from 'the other thread' mentioned above.
 
We use a script that runs every five minutes via cron and compares the current IP to an IP in a tmp file. If it's different, it notifies us that it changed and writes the new IP to the tmp file. Nothing special, but it works for our handful of sites using DHCP for public IPs (ADSL links).

An event-based trigger would be more efficient, but it's not like running sh/grep/awk every five minutes is exactly taxing. :)
 
Back
Top