xenu_nntp/lib/nntp/tiny/host.py
2024-12-04 16:32:23 -05:00

26 lines
567 B
Python

class Host():
@staticmethod
def is_ipv6(value: str):
return value.find(':') >= 0
@staticmethod
def is_ipv4(value: str):
parts = value.split('.')
if len(parts) > 4 or len(parts) == 0:
return False
for part in parts:
if not part.isdecimal():
return False
num = int(part)
if num > 255:
return False
return True
@staticmethod
def is_hostname(value: str):
return not (Host.is_ipv6(value) and Host.is_ipv4(value))