Here's a trivial patch to add support for the IPv6 AAAA record type. I've only actually tested the unpacker half, not the packer. But with this patch, DNS.lazy.dnslookup(..., DNS.Type.AAAA) returns a correct IPv6 address.
I don't know when Python's socket module got inet_pton(); if it was recent it might be worth putting that import into a try block or something.
support for packing and unpacking AAAA records
This is tricky. Currently, AAAA queries return a 16 octet string/bytes. Pyspf, depends on that - easily fixed, but perhaps other clients depend on that. More generally, sometimes you want the raw bytes, and sometimes you want the human readable form. For instance, in pyspf, converting bytes to string and then back to bytes would be inefficient. (But is that premature optimization?) I did wish to be consistent and retrieve A records as bytes also.
So maybe the solution is this: add a "RAW" flag that returns all values as raw bytes, and add the AAAA support. Unsupported RRs will still fallback to RAW, and that could possibly break some client besides pyspf - but it might be unlikely. I did mention this on the pymilter mailling list, but I'll mention it again before making the change.
About inet_pton - is has been around a long time, but only supports IP6 if python is compiled with IP6 support (which depends on system libraries for IP6 parsing). Most distros now do compile with IP6 support .
Pyspf uses this hack:
if hasattr(socket,'has_ipv6') and socket.has_ipv6:
def inet_ntop(s):
return socket.inet_ntop(socket.AF_INET6,s)
def inet_pton(s):
return socket.inet_pton(socket.AF_INET6,s)
else:
from SPF.pyip6 import inet_ntop, inet_pton
The pyip6 module reimplements inet_pton and inet_ntop for IP6 in pure python.
Something like the pyip6 module has been introduced as the IPy, and is
now included in Fedora. It provides an IP class that parses and classifies
IP4 and IP6 addresses.
So, what to do?
1) make pyip6 global for use by both pyspf and pydns
2) switch to IPy for pydns and pyspf
3) assume any modern python supports IP6 natively and just
use socket.inet_pton