Skip to content

Instantly share code, notes, and snippets.

@scottwallacesh
Created June 14, 2017 10:27
Show Gist options
  • Save scottwallacesh/ebe04c7c26e08d7895175de137898e08 to your computer and use it in GitHub Desktop.
Save scottwallacesh/ebe04c7c26e08d7895175de137898e08 to your computer and use it in GitHub Desktop.
Small Python function to validate an IP address
def is_valid_ip(ip):
m = re.match(r"^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$", ip)
return bool(m) and all(map(lambda n: 0 <= int(n) <= 255, m.groups()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment