Skip to content

Instantly share code, notes, and snippets.

@thepacketgeek
Created December 4, 2013 22:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save thepacketgeek/7796394 to your computer and use it in GitHub Desktop.
Save thepacketgeek/7796394 to your computer and use it in GitHub Desktop.
Check for a valid IP address
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