Skip to content

Instantly share code, notes, and snippets.

@Highstaker
Created November 17, 2016 16:13
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 Highstaker/55cbe009552bc5bd3061f912d93a9f02 to your computer and use it in GitHub Desktop.
Save Highstaker/55cbe009552bc5bd3061f912d93a9f02 to your computer and use it in GitHub Desktop.
Simple IP validation with Python and regex
import re
number_pattern = r"(([1-9]?[0-9])|(1[0-9][0-9])|(2[0-4][0-9])|(25[0-5]))"
IP_validator = re.compile(r'^{0}(\.{0}){1}$'.format(number_pattern, "{3}"))
def is_valid_IP(strng):
return bool(IP_validator.match(strng))
is_valid_IP("12.34.56.708")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment