Binary adresse for localhost

Jimmy Retzlaff jimmy at retzlaff.com
Thu Jun 19 12:55:24 CEST 2003


Benoit BESSE (benoit.besse at club-internet.fr) wrote:
> for "224.4.0.1" the binary adresse is 0xe0040001L.
> What is the corresponding convertion for 127.0.0.1.

I'll offer a few approaches in the hopes of making this somewhat Python
related. :)

>>> import socket
>>> socket.inet_aton('224.4.0.1')
'\xe0\x04\x00\x01'
>>> socket.inet_aton('127.0.0.1')
'\x7f\x00\x00\x01'

>>> map(hex, [127, 0, 0, 1])
['0x7f', '0x0', '0x0', '0x1']

>>> '0x%.2x%.2x%.2x%.2x' % (127, 0, 0, 1)
'0x7f000001'


Jimmy





More information about the Python-list mailing list