sorting on IP addresses
che at debian.org
Mon Feb 5 23:25:06 CET 2001
>>>>> "Sam" == Sam Wun <swun at esec.com.au> writes:
Sam> Hi, Does anyone know what is the quickly way to sort a list
Sam> of IP addresses?
Sam> ie. 18.104.22.168 should be larger than 22.214.171.124
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 126.96.36.199 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+ -- http://www.debian.org/
More information about the Python-list