Skip to content

Instantly share code, notes, and snippets.

@fndiaz
Last active August 29, 2015 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fndiaz/e890dfda2037f8f64e31 to your computer and use it in GitHub Desktop.
Save fndiaz/e890dfda2037f8f64e31 to your computer and use it in GitHub Desktop.
import iplib
ips = ["10.4.4.6", "10.4.4.250", "10.4.4.100", "10.4.4.5", "10.4.4.25"]
def ip_compare(x, y):
""" Compare two IP addresses. """
# Convert IP addresses to decimal for easy comparison
dec_x = int(iplib.convert(x, "dec"))
dec_y = int(iplib.convert(y, "dec"))
if dec_x > dec_y:
return 1
elif dec_x == dec_y:
return 0
else:
return -1
ips.sort(ip_compare) # Sort in place
print ips
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment