Get the ipv6 address from a interface

"Martin v. Löwis" martin at v.loewis.de
Fri Apr 10 00:46:07 CEST 2009


> I'm not 100% sure what you're trying to do, but the above is horribly 
> non-portable.  You probably want to be looking at socket.getpeername() and 
> socket.getsockname().

This only works if you are actually connected. I think he wants to find
out the local address without actually connecting.

> In general, concepts like "the address of an interface" are difficult.  In 
> many OS's, a given interface may have multiple addresses.  This is 
> especially true in IPv6 where you've have both link local and global 
> unicast addresses on the same interface.

In Linux, you can only have one IPv4 address per interface (and you have
to use alias interfaces, such as eth0:0, to assign multiple addresses
to a physical link).

For IPv6 and Linux, you are right.

> 
> Can you back up a few steps and describe what it is that you're trying to 
> do, i.e. the use case?

I guess he wants to do the equivalent of ifconfig.

Regards,
Martin



More information about the Python-list mailing list