diff --git a/rdns-manager b/rdns-manager index f468ee1..879a1ed 100755 --- a/rdns-manager +++ b/rdns-manager @@ -39,9 +39,9 @@ sub validate_domain { return 1 if is_domain $domain; return 0; } -sub is_ip { +sub validate_ip { my $ip = shift; - return 1 if is_public_ipv4 $ip || is_public_ipv6 $ip; + return 1 if is_public_ipv4($ip) || is_public_ipv6($ip); return 0; } sub get_arpa { @@ -63,7 +63,8 @@ sub does_fqdn_match { $p = $r->search($fqdn, 'AAAA') unless is_public_ipv4 $ip; return 0 unless defined $p; my @res = $p->answer; - return 1 unless scalar @res < 1 || $res[0]->address ne $ip; + #due to IPv6 shortening, we need to use Net::IP here + return 1 unless scalar @res < 1 || Net::IP->new($res[0]->address)->ip ne Net::IP->new($ip)->ip; return 0; } sub confirm_rdns { @@ -111,11 +112,10 @@ GetOptions #get IP and domain, validate. my $ip = shift or nicedie "No IP given!"; $prefixlen = $1 if $ip =~ s/\/([0-9]+)//; #split off prefixlen (if given) into variable for later use -nicedie "Invalid IP address '$ip'!" unless is_ip $ip; +nicedie "Invalid IP address '$ip'!" unless validate_ip $ip; my $domain = shift or nicedie "No FQDN given!" unless $fsync || $reset || $delptr; #conditionally allow the user to not specify a fqdn nicedie "Invalid FQDN '$domain'!" if defined $domain && !validate_domain $domain; $domain =~ s/([a-zA-Z])$/$1./; #Append final period if it doesn't exist + #main flow -print "Does $domain match $ip? ".does_fqdn_match $domain, $ip; -print "\nDoes $ip reverse to $domain? ".confirm_rdns $domain, $ip;