sorting on IP addresses

Ben Gertzfield che at
Mon Feb 5 23:25:06 CET 2001

>>>>> "Sam" == Sam Wun <swun at> writes:

    Sam> Hi, Does anyone know what is the quickly way to sort a list
    Sam> of IP addresses?

    Sam> ie. should be larger than

If you're using Python 1.6 or greater, the socket module includes
inet_aton and inet_ntoa functions, used for converting IP addresses
from format to the 4-byte "packed IP" representation.

You can then just use a normal sort on the packed IPs.


Brought to you by the letters P and R and the number 1.
"Atatakaku natta kara, otaku to uchi no kazoku de, nani ka shimasen ka?"
Debian GNU/Linux maintainer of Gimp and GTK+ --

More information about the Python-list mailing list