Sorting a list of IPs should be easy using some linux utility or another, right? It is, and here is how to do it.
Say your list of IPs, one per line, is contained in the file tmp. Then the proper sort command is:
$ sort -n -t . -k1,1 -k2,2 -k 3,3 -k4,4 tmp
If you want things in descending order just do a -nr instead of -n at the beginning.
This sort solves the problem that for instance 9 is evaluated as being greater than 115, for instance!