#!/usr/bin/perl -w use strict; use LWP::Simple; # # utilize zoneedit's program to edit website dns ip info. # the current used ip for dns is stored in $ip_file, which # is used to check against. If the current used dns ip is different # from the current ip we have, update ip and $ip_file. otherwise do null. # # it works best with cron job to monitor your ip change and update it in time. # # file path to store the current used ip my $ip_file = "/home/qiang/script/ip.txt"; # sites used to get your domain ip. my $checkip_1 = "http://dynamic.zoneedit.com/checkip.html"; my $checkip_2 = "http://whatismyip.com"; # the regex you used to match your ip on the site. my $ipmatch_2 = qr(Your IP is ); my $ipmatch_1 = qr(Current IP Address: ); # lynx path my $lynx = '/usr/local/bin/lynx'; # authentication info for zoneedit my $uname = "uname"; my $pwd = "passwd"; # domains need to be updated my $domain_1 = 'http://dynamic.zoneedit.com/auth/dynamic.html?host=www.easyya.com'; my $domain_2 = 'http://dynamic.zoneedit.com/auth/dynamic.html?host=easyya.com'; ######################## no need to edit below from here ################### my $old_ip = &get_old_ip; my $new_ip = &get_current_ip; # continue if current ip is different than the old one. unless ($old_ip eq $new_ip) { my $code1 = `$lynx -source -auth=$uname:$pwd $domain_1`; my $code2 = `$lynx -source -auth=$uname:$pwd $domain_2`; print $new_ip," ",$code1," ",$code2,"\n"; open F,">$ip_file" or die $!; print F $new_ip; close F; } sub get_old_ip { my $ip; if (-e $ip_file) { open F,$ip_file or die $!; $ip = ; chomp $ip; close F; } else { $ip = "1.2.3.4"; } return $ip; } sub get_current_ip { my ($checkip,$ipmatch) = &_get_checkip_site; my $content = get($checkip); die "Couldn't get $checkip!" unless defined $content; my ($ip) = $content =~ /$ipmatch(\d+\.\d+.\d+\.\d+)/; return $ip; } sub _get_checkip_site { my $header = head($checkip_2); unless ($header) { return ($checkip_1,$ipmatch_1); } return ($checkip_2,$ipmatch_2); }