Skip to content

Instantly share code, notes, and snippets.

@james-see
Created May 13, 2022 17:18
Show Gist options
  • Save james-see/dedad853345e192146766e35c569b58b to your computer and use it in GitHub Desktop.
Save james-see/dedad853345e192146766e35c569b58b to your computer and use it in GitHub Desktop.
check for ip4 in python
import re
class IsIPv4Address:
# noinspection PyPep8Naming
@classmethod
def is_IPv4_address(cls, input_str: str) -> bool:
pattern = r"\b((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.|$)){4}\b"
if re.fullmatch(pattern, input_str):
return True
return False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment