#!/usr/bin/perl use strict; use LWP::Simple; use Sys::Syslog qw( :DEFAULT setlogsock); my $dir = "/root/script/"; my $emailadd = "your\@email.com"; my $fromadd = "ipwatch\@yourmachine"; chdir $dir; my $current_ip = get('http://www.chisono.it/ip.asp') || logit('err', "Cannot retrieve the IP address: $!\n"); my ($a1, $a2, $a3, $a4) = split /\./, $current_ip; open FILE, "myip.txt" or logit('err', "Cannot open the file: $!\n"); my $readip = ; my ($b1, $b2, $b3, $b4) = split /\./, $readip; if ($readip eq $current_ip) { logit('info', "Address not changed\n"); } else { logit('info', "Address changed: old IP: $readip ; New IP: $current_ip\n"); getstore('http://www.chisono.it/ip.asp', 'myip.txt'); system("mailx -s \"IP changed!\" -a \"From: IPWatch <$fromadd>\" $emailadd < myip.txt") || logit('err', "Cannot send the email!\n"); } sub logit { my ($priority, $msg) = @_; return 0 unless ($priority =~ /info|err|debug/); setlogsock('unix'); openlog($0, 'pid,cons', 'user'); syslog($priority, $msg); closelog(); return 1; }