Convert IPv6 address to binary representation on 2.x/Windows

Philipp Hagemeister phihag at phihag.de
Wed Mar 4 16:50:33 EST 2009


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

Hi Martin,

Martin v. Löwis wrote:
> I do wonder why you need a binary representation of an IPv6 address...
I'd like to subscribe to an IPv6 multicast address via
socket.setsockopt(IPPROTO_IPV6, IPV6_JOIN_GROUP, binary_address).

> Yes, writing your own routine is certainly an option.
Is it the preferred one? Because I need this for two purposes: My own
code as well as the python multicast example Demo/socket/mcast.py [1].

> Alternatively,
> you can try one of the IP address manipulation libraries, such as
> ipaddr, or netaddr. Disclaimer: I haven't checked whether these support
> the requested functionality; please report back when you know.
ipaddr[2] has functions that would certainly helpful (int(IP('::1'))
yields 1), but not quite the one I'm looking for, although it would be
trivial to write it. But then, why should I need ipaddr?
netaddr[3] has the function I'm looking for Addr('::1').packed(), but
it's way over the top for this purpose; an assembler implementation
would be more readable.

Kind regards,

Philipp Hagemeister

[1] http://bugs.python.org/issue5379
[2] http://ipaddr-py.googlecode.com
[3] http://code.google.com/p/netaddr/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEAREKAAYFAkmu96cACgkQ9eq1gvr7CFzlAwCgrMXI6PVrBGXP5phvv2Fk//9b
pQ0An37q6/KNZtIP4OvzYh68NXg4HCU4
=bNqC
-----END PGP SIGNATURE-----



More information about the Python-list mailing list