do nothing if IP does not change
This commit is contained in:
parent
3511cf93ec
commit
4227ca80ce
20
sshdyndns
20
sshdyndns
@ -30,6 +30,7 @@ my $help = 0;
|
|||||||
my $tsigalgo = 'hmac-sha256';
|
my $tsigalgo = 'hmac-sha256';
|
||||||
my ($tsigname, $tsigkey, $server, $verbose, $tsig);
|
my ($tsigname, $tsigkey, $server, $verbose, $tsig);
|
||||||
my ($old_rr, $new_rr, $update, $resolver, $reply, $ip);
|
my ($old_rr, $new_rr, $update, $resolver, $reply, $ip);
|
||||||
|
my @answer;
|
||||||
|
|
||||||
GetOptions("help|?" => \$help,
|
GetOptions("help|?" => \$help,
|
||||||
"verbose" => \$verbose,
|
"verbose" => \$verbose,
|
||||||
@ -59,6 +60,21 @@ if(exists $ENV{SSH_CLIENT} &&
|
|||||||
pod2usage(1);
|
pod2usage(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$resolver = new Net::DNS::Resolver(recurse => 0);
|
||||||
|
$resolver->nameservers($server);
|
||||||
|
$resolver->port($port);
|
||||||
|
|
||||||
|
$reply = $resolver->query($label, 'A');
|
||||||
|
|
||||||
|
if ($reply && $reply->header->rcode eq 'NOERROR' &&
|
||||||
|
scalar($reply->answer) == 1) {
|
||||||
|
@answer = $reply->answer;
|
||||||
|
if ($answer[0]->type eq 'A' && $answer[0]->address eq $ip) {
|
||||||
|
say 'no change, nothing to do' if ($verbose);
|
||||||
|
exit (0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$old_rr = rr_del("$label A");
|
$old_rr = rr_del("$label A");
|
||||||
$new_rr = rr_add("$label $ttl A $ip");
|
$new_rr = rr_add("$label $ttl A $ip");
|
||||||
|
|
||||||
@ -83,10 +99,6 @@ if (defined $tsigname && defined $tsigkey) {
|
|||||||
|
|
||||||
say $update->string if ($verbose);
|
say $update->string if ($verbose);
|
||||||
|
|
||||||
$resolver = new Net::DNS::Resolver;
|
|
||||||
$resolver->nameservers($server);
|
|
||||||
$resolver->port($port);
|
|
||||||
|
|
||||||
$reply = $resolver->send($update);
|
$reply = $resolver->send($update);
|
||||||
|
|
||||||
if ($reply) {
|
if ($reply) {
|
||||||
|
Loading…
Reference in New Issue
Block a user