#!/usr/bin/perl -w # This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License. # http://herselfswebtools.com # Linda MacPhee-Cobb" # modified by Chris Jones, cj@cr-jay.ca, Dec. 2002 # a tool to get non static ip address when #you have a router installed, this also works if you do not #have a router. #works on windows, linux, unix # Windows: use the scheduler to check periodically # linux/unix: use cron to check periodically #compares today's IP with previous. Sends an email if the IP has changed. use strict; use Net::SMTP; use LWP::Simple; ##*********************************** #you need to edit the following: my $smtphost = "your-smtp-host.com"; my $from = "me\@mypop.com"; my $to = "somone\@theirpop.com"; #******************************** #get page with ip info my $html = get( 'http://checkip.dyndns.org' ); #print $html; #parse the IP address from the reply # note, does not check for valid IP just that the construct is there $html =~ /(\d+)\.(\d+)\.(\d+)\.(\d+)/; my $a = "$1"; my $b = "$2"; my $c = "$3"; my $d = "$4"; my $ip = "$a.$b.$c.$d"; my $ipfile = 'ip.dat'; my $prev_ip = ""; if( open S, "$ipfile" ) { $prev_ip = ; close S; } if (!($ip eq $prev_ip)) { my $smtp = Net::SMTP->new("$smtphost"); # First the envelope bits $smtp->mail("$from"); $smtp->to("$to"); # Now for the message itself $smtp->data(); $smtp->datasend("From: $to\n"); $smtp->datasend("To: $from\n"); $smtp->datasend("Subject: IP \n"); $smtp->datasend("\n"); $smtp->datasend("IP Changed: was $prev_ip, now: $ip\n"); $smtp->dataend(); $smtp->quit; } #store the IP address for next comparison open S, ">$ipfile"; print S $ip; close S;