Last active
August 29, 2015 14:18
-
-
Save fndiaz/e890dfda2037f8f64e31 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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