Skip to content

Instantly share code, notes, and snippets.

@blovett
Created July 9, 2011 19:51
Show Gist options
  • Save blovett/1073888 to your computer and use it in GitHub Desktop.
Save blovett/1073888 to your computer and use it in GitHub Desktop.
Stupid conversion script for converting IPv6 addresses to PTR notation
#!/usr/bin/perl
while (<>) {
chomp;
if (/IN\s*PTR/) {
if (/^(.*)\s+IN\s+PTR\s+(\w.*)/) {
my $v6_addy = $1;
my $ptr_val = $2;
my $ipv6_reverse = `sipcalc -r $v6_addy | grep ip6.arpa | tail -n1`;
chomp($ipv6_reverse);
if ($ipv6_reverse) {
print "$ipv6_reverse\tIN\tPTR\t$ptr_val\n";
} else {
print "; $_\t;; invalid!\n";
print STDERR "Warning! Could not properly convert \'$v6_addy\' to nibble form!\n";
}
}
} else {
print "$_\n";;
}
}
% cat master/0.0.1.0.8.b.d.0.1.0.0.2.ip6.arpa.tmpl
$TTL 1h
@ IN SOA dns.example.com. hostmaster.example.com. (
2011070901 ; Serial # - bump up if file chg'd
30m ; Refresh secondary
5m ; Retry secondary
7d ; Expire secondary
5m ) ; Minimum ttl
IN NS dns.example.com.
IN NS dns2.example.com.
;
; 2001:db8:100::/64
;
2001:db8:100::1 IN PTR gw1.example.com.
;
; 2001:db8:100:f00d::/64
;
2001:db8:100:f00d::1 IN PTR gw2.example.com.
2001:db8:100:f00d::2 IN PTR host1.example.com.
; vim: ts=5 tw=0
% perl ./convert_to_bind.pl master/0.0.1.0.8.b.d.0.1.0.0.2.ip6.arpa.tmpl
$TTL 1h
@ IN SOA dns.example.com. hostmaster.example.com. (
2011070901 ; Serial # - bump up if file chg'd
30m ; Refresh secondary
5m ; Retry secondary
7d ; Expire secondary
5m ) ; Minimum ttl
IN NS dns.example.com.
IN NS dns2.example.com.
;
; 2001:db8:100::/64
;
1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.1.0.8.b.d.0.1.0.0.2.ip6.arpa. IN PTR gw1.example.com.
;
; 2001:db8:100:f00d::/64
;
1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.d.0.0.f.0.0.1.0.8.b.d.0.1.0.0.2.ip6.arpa. IN PTR gw2.example.com.
2.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.d.0.0.f.0.0.1.0.8.b.d.0.1.0.0.2.ip6.arpa. IN PTR host1.example.com.
; vim: ts=5 tw=0
% named-checkzone 0.0.1.0.8.b.d.0.1.0.0.2.ip6.arpa master/0.0.1.0.8.b.d.0.1.0.0.2.ip6.arpa
zone 0.0.1.0.8.b.d.0.1.0.0.2.ip6.arpa/IN: loaded serial 2011070901
OK
@tazboyz16
Copy link

tazboyz16 commented Dec 10, 2019

sipcalc -r 2001:db8:100::1 | egrep '\.ip6.arpa\.' this would remove the need for the tail -n1 command

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment