Created
April 20, 2011 20:16
-
-
Save sugar84/932612 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use common::sense; | |
use Net::DNS::DynDNS; | |
use LWP::Simple qw/get/; | |
my $file_ip = "result.dat"; | |
my $user = "user"; | |
my $passw = "paswword"; | |
my $domain = "domain.dyndns.org"; | |
my @check_urls = ( | |
"http://checkmyip.org/", # <h1>Your IP address is 93.81.78.125</h1> | |
"http://checkmyip.com/", # <div id="ip">Your local IP address is<br>93.81.78.125</div> | |
"http://whatismyipaddress.com/", #<h2 style="margin: 0pt;">IP Information: <span class="ip blue">93.81.78.125</span></h2> | |
"http://www.whatismyip.com/automation/n09230945.asp", | |
"http://checkip.dyndns.org", # <body>Current IP Address: 93.81.78.125</body> | |
); | |
my @handlers = ( | |
sub { | |
my $cont = shift; | |
my ($ip) = $cont =~ m|<h1>.+?((:?\d{1,3}\.){3}\d{1,3})</h1>|; | |
return $ip; | |
}, | |
sub { | |
my $cont = shift; | |
my ($ip) = $cont =~ m|div id="ip">.+?((:?\d{1,3}\.){3}\d{1,3})</div>|s; | |
return $ip; | |
}, | |
sub { | |
my $cont = shift; | |
my ($ip) = $cont =~ m|<span class="ip blue">.*?((:?\d{1,3}\.){3}\d{1,3}).*?</span></h2>|s; | |
return $ip; | |
}, | |
sub { | |
my $cont = shift; | |
my ($ip) = $cont =~ m|((:?\d{1,3}\.){3}\d{1,3})|; | |
return $ip; | |
}, | |
sub { | |
my $cont = shift; | |
my ($ip) = $cont =~ m|<body>.+?((:?\d{1,3}\.){3}\d{1,3})</body>|; | |
return $ip; | |
}, | |
); | |
open my $fh, "<", $file_ip | |
or warn "can't open file_ip: $file_ip $!"; | |
my ($last_ip) = <$fh>; | |
close $fh; | |
undef $last_ip if $last_ip !~ /^(\d{1,3}\.){3}\d{1,3}$/; | |
my $step = int rand( scalar @check_urls ); | |
my $new_ip = $handlers[$step]->( get($check_urls[$step]) ); | |
my $ip; | |
if ($new_ip ne $last_ip && $new_ip =~ /^(\d{1,3}\.){3}\d{1,3}$/) { | |
my $client = Net::DNS::DynDNS->new($user, $passw); | |
$ip = $client->update($domain, $new_ip); | |
} | |
if ($ip && $ip =~ /^(\d{1,3}\.){3}\d{1,3}$/) { | |
open my $fh, ">", $file_ip | |
or die "can't open file_ip: $file_ip $!"; | |
print $fh $ip; | |
close $fh; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment