#!/usr/bin/perl #==============================================================================# # Hard coded settings # The hostname we are updating use constant HOSTNAME => 'puerto.brock-family.org'; # The web page with the data, and the pattern to extract it use constant ROUTER_PAGE => 'http://admin:XXXXXXX@192.168.0.1/info_main.html'; use constant ROUTER_PATTERN => qr/(\d+\.\d+\.\d+\.\d+)/; # First IP address # EasyDNS details use constant EASYDNS_USER => 'userfoo'; use constant EASYDNS_PASS => 'XXXXXX'; # #==============================================================================# use strict; use warnings; use LWP::Simple; use DNS::EasyDNS; use File::Spec::Functions qw(catfile tmpdir); #==============================================================================# my $cache_file = catfile(tmpdir,"easydns.ip"); my $old_ip = ''; if (open(my $inp,"< $cache_file")) { chomp($old_ip = <$inp>); } else { warn "Can't read $cache_file: $!\n"; } if (get(ROUTER_PAGE) =~ ROUTER_PATTERN) { my $ip = $1; if ($ip ne $old_ip) { print "IP address changed: $old_ip -> $ip\n"; if (DNS::EasyDNS->new->update( username => EASYDNS_USER, password => EASYDNS_PASS, hostname => HOSTNAME, )) { print "Update succeeded\n"; if (open(my $outp,"> $cache_file")) { print $outp "$ip\n"; } else { warn "Can't write $cache_file: $!\n"; } } else { print "Update failed: [$@]\n"; } } else { print "IP still $ip\n"; } } else { warn "Could not get IP"; } #==============================================================================#