http://www.perlmonks.org?node_id=1006276

Arkevius has asked for the wisdom of the Perl Monks concerning the following question:

Hello all! I manage a Linux Ubuntu 12.04 LTS server for a local police department. They have cable internet, and unsure of whether or not their ISP provided them with a static or dynamic IP address, I wrote a perl script to notify me if the IP address should ever change (since I manage the server remotely). I only have 1 problem with this scripts. Sometimes, it seems to fetch a "blank" when trying to resolve the IP. It sees the "blank" address as new, so it will then send me an e-mail saying the address has changed. Then an hour later (when the cronjob goes off every hour on the hour), it will fetch the correct IP addy, and then notify again of the "new change." If I had to guess, it's during the actual resolving of the IP address and fetching that information that it seems to get this null IP. I've pasted my code below for review. What do you all think?
#! /usr/bin/perl -w use Net::SMTP::SSL; # FETCH THE PUBLIC IP ADDRESS $ip = `wget http://automation.whatismyip.com/n09230945.asp -O - -q ; e +cho`; chomp ($ip); # OPEN FILE THAT CONTAINS THE IP ADDRESS # AS OF THE LAST TIME THE SCRIPT WAS RAN open FILE, "<", "/root/scripts/currentIP" or die $!; $currentIP = <FILE>; chomp ($currentIP); close FILE; # COMPARE THE OLD IP AND THE FETCHED IP # FOR DIFFERENCES if ($currentIP ne $ip) { #IP HAS CHANGED; EMAIL ADMIN THE NEW IP #AND THEN CHANGE THE IP RECORD FILE open FILE, ">", "/root/scripts/currentIP" or die $!; print FILE $ip; close FILE; &emailAdmin; } # E-MAIL SUB ROUTINE # (I HAVE EXIM4 SETUP TO FORWARD TO GOOGLE # SMARTHOST SO I CAN RECEIVE MAIL AS ROOT) sub emailAdmin { my $headers = "PD IP Change\nFrom: ipUpdater Script\nUser-Agent: H +eirloom mailx 12.5 6/20/10\nMIME-Version: 1.0\nContent-Type: text/pla +in; charset=us-ascii\nContent-Transfer-Encoding: 7bit\n"; my $to = "root"; my $body = "The public IP address for the BPDServer has changed.\n +\nNew IP: $ip\nOld IP: $currentIP\n."; system("echo \"$body\" | mail -s \"$headers\" \"$to\""); }