inet_ntoa
Adrian Eyre
a.eyre at optichrome.com
Tue Mar 7 08:44:19 EST 2000
>>> Does anyone know if the inet_ntoa function in "arpa/inet.h" is
>>> implemented in python anywhere. I can't find it in the docs. Or, is
>>> there a similar func in python to convert integral network addresses
>>> into a dotted quad string??
>> Try the struct module.
> def getip(long):
> return
string.join(map(str,unpack('4B',pack('<L',string.atol(long)))),'.')
Am I missing something here:
>>> import socket
>>> print socket.inet_ntoa.__doc__
inet_aton(packed_ip) -> ip_address_string
Convert an IP address from 32-bit packed binary format to string format
>>> socket.inet_ntoa("\012\000\000\001")
'10.0.0.1'
>>> ^D
Just noticed the docstring is wrong.
-----------------------------------------------------------------
Adrian Eyre <a.eyre at optichrome.com> - http://www.optichrome.com
More information about the Python-list
mailing list