[Tutor] IP sorting

ccl chrislubrecht@home.com
Wed, 26 Dec 2001 21:27:54 -0500


This may be somewhere, and I am just being lazy, but its something I need 
to fix...

I am currently writing a script to analyze proxy server logs. One section 
of the script scrubs out the IP addresses, counts them and sorts them and 
prints them in a nice ordered way with the IP, then the number of hits. 
(ie. "192.168.1.5 ----- 356 hits")

Basically, what I am doing is creating a dictionary with the IP as the key, 
and the result of string.count() as the entry.

then I do...

dead_bishop = ip_dictionary.keys()
dead_bishop.sort()
for item in dead_bishop:
  print item," ---- ",ip_dictionary[item]," hits"


All is good, it works well, however it only sorts to the second place of 
the last octet. For example...

192.168.100.118 --- 5 hits
192.168.100.119 --- 10 hits
192.168.100.12 --- 3 hits
192.168.100.120 --- 22 hits

How do I get the 192.168.100.12 to go where it supposed to (at the beginning)?