-
-
Save dvinciguerra/a52cbb71bffaf0459046 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 strict; | |
use warnings; | |
use LWP::Simple; | |
# constants | |
use constant { | |
TMPDIR => '/tmp', | |
NSFILE => '/tmp/ddns.ip' | |
}; | |
# getting ip | |
my $ip = get_ip(); | |
# check | |
if ( !-e NSFILE ) { | |
open my $fh, '>', NSFILE or die "Error: $!"; | |
print $fh "0.0.0.0"; | |
close $fh; | |
} | |
my $nsfile; | |
open my $fhreader, NSFILE or die "Error reading: $!"; | |
$nsfile = join( '', <$fhreader> ); | |
chomp $nsfile; | |
close $fhreader; | |
# ip not equals | |
if ( $nsfile ne $ip ) { | |
# TODO coloca aqui o update do ip | |
my $keyname = "tchaves"; | |
my $hash = "BAb8A39m6gXtmraR1iqUkbnrBNer3vSnZ1T1+HC9djnY0RdJ0+eaYswsB9m5oMkQ56lV6DdFrI9jQ8nnz2VvkQ=="; | |
my $ns_server = "ns1.tchaves.com.br"; | |
my $zone = "din.tchaves.com.br"; | |
my $host = "teste.din.tchaves.com.br"; | |
my $nsupdate = "/usr/bin/nsupdate -y $keyname:$hash"; | |
my $exec = "server $ns_server\n | |
zone $zone\n | |
update delete $host A\n | |
update add $host 60 A $ip\n | |
send | |
quit"; | |
my $res = qx{ $exec | $nsupdate }; | |
open my $fh, '>', NSFILE or die "Error: $!"; | |
print $fh "$ip"; | |
close $fh; | |
} | |
else { | |
print "Endereço de IP não mudou!\n"; | |
} | |
sub get_ip { | |
my $html = get "http://meuip.datahouse.com.br"; | |
if ($html) { | |
$html =~ m/(\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3})/; | |
return $1 if $1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment