INNER CODE UNIT · Python
is_valid_target
HaxL0p4/L0p4Map · ui/app.py:195
def is_valid_target(text: str) -> bool:
text = text.strip()
if not text:
return False
try:
ipaddress.ip_address(text)
return True
except ValueError:
pass
try:
ipaddress.ip_network(text, strict=False)
return True
except ValueError:
pass
if re.match(r"^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}-\d{1,3}$", text):
return True
hostname_re = re.compile(
r"^(?!-)[a-zA-Z0-9\-]{1,63}(?:\.[a-zA-Z0-9\-]{1,63})*\.?$"