I'm trying to sort IP Addresses which I'm reading into a python script and printing out. The code that I've drafted up reads and prints the contents of a file (see example)
#!/usr/bin/python
f = open('file.txt', 'r')
file_contents = f.read()
print (file_contents)
f.close()
My issue is how do I take that importing of IP Addresses and sort them correctly? At the command line I would normally pass the file through a simple sort command (sort -n -t . -k 1,1 -k 2,2 -k 3,3 -k 4,4 ). But how can I get python to sort the IPs it's reading from the file so the output is sorted correctly, taking into consideration the 0-255 numbering schema for each octet of an IP?
Thanks,