Created
December 4, 2013 22:01
-
-
Save thepacketgeek/7796394 to your computer and use it in GitHub Desktop.
Check for a valid IP address
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
def valid_ip(address): | |
try: | |
host_bytes = address.split('.') | |
valid = [int(b) for b in host_bytes] | |
valid = [b for b in valid if b >= 0 and b<=255] | |
return len(host_bytes) == 4 and len(valid) == 4 | |
except: | |
return False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment