IP address to binary conversion

Alex Martelli aleaxit at yahoo.com
Fri Jun 15 12:15:54 CEST 2001


"Jeroen Wolff" <jwolff at ision.nl> wrote in message
news:vqajitkao6tvll7ads8v84nbatp1hhr8jn at 4ax.com...
>
> >
> >>>> host = n & mask
> >>>> net = n - host
>
> >>>> print "net: %X  host: %X" % (net, host)
> >net: C0000000  host: A80201
> >
> Is there a way back to present the calculated results in a doted
> decimal notation?

>>> import socket, struct
>>> print socket.inet_ntoa(struct.pack("!L",host))
0.168.2.1
>>>


Alex






More information about the Python-list mailing list