I’m needing to work out the IPv6 reverse zone for a given IPv6 CIDR prefix, that is a prefix with number of bits in the network on the end after a forward slash. e.g.:
- 2001:ba8:1f1:f004::/64 → 4.0.0.f.1.f.1.0.8.a.b.0.1.0.0.2.ip6.arpa
- 4:2::/32 → 184.108.40.206.220.127.116.11.ip6.arpa
- 2001:ba8:1f1:400::/56 → 0.0.4.0.1.f.1.0.8.a.b.0.1.0.0.2.ip6.arpa
I had a quick look for a module that does it, but couldn’t find one, so I hacked this subroutine together:
Is there a more elegant way? Is there a module I can replace this with?
- Arbitrary prefix length
- Use of ‘::’ anywhere legal in the address