python-iptools icon indicating copy to clipboard operation
python-iptools copied to clipboard

IPv6 string representation

Open jimmykao89 opened this issue 4 years ago • 2 comments

Hi,

I was wondering, do the strings output from iptools conform to RFC 5952 for IPv6? Thanks

jimmykao89 avatar Aug 31 '20 20:08 jimmykao89

I believe it mostly is, but there is not a strong conformance test suite to ensure this. I tried the explicit examples from https://tools.ietf.org/html/rfc5952#page-10 and they all seem to be output as the RFC suggests:

>>> from iptools.ipv6 import (ip2long, long2ip)
>>> long2ip(ip2long("2001:0db8::0001"))
'2001:db8::1'
>>> long2ip(ip2long("2001:db8:0:0:0:0:2:1"))
'2001:db8::2:1'
>>> long2ip(ip2long("2001:db8::1:1:1:1:1"))
'2001:db8:0:1:1:1:1:1'
>>> long2ip(ip2long("2001:db8:0:0:1:0:0:1"))
'2001:db8::1:0:0:1'

There is currently no special output handling for IPv4-Mapped addresses. This is recommended in RFC 5952, but not required.

>>> long2ip(ip2long("::ffff:192.0.2.1"))
'::ffff:c000:201'

bd808 avatar Aug 31 '20 20:08 bd808

Ok, thanks for the speedy reply!

jimmykao89 avatar Aug 31 '20 20:08 jimmykao89