Skip to content

Instantly share code, notes, and snippets.

@danielgoncalves
Created September 5, 2011 21:46
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 danielgoncalves/1195995 to your computer and use it in GitHub Desktop.
Save danielgoncalves/1195995 to your computer and use it in GitHub Desktop.
Validate an IPv4 address.
def is_ip(value):
"""IP simple validation in response to blog post http://goo.gl/L9cKh"""
try:
bytes = [int(e) for e in value.split('.') if 0 <= int(e) <= 255)]
except ValueError:
return False
return len(bytes) == 4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment