mirror of
https://github.com/fergalmoran/bitchmin.git
synced 2026-02-15 12:24:05 +00:00
27 lines
695 B
Python
27 lines
695 B
Python
import ipaddress
|
|
import re
|
|
|
|
import sys
|
|
|
|
|
|
def is_valid_ip(address):
|
|
try:
|
|
ip = ipaddress.ip_address(address)
|
|
print('%s is a correct IP%s address.' % (ip, ip.version))
|
|
return True
|
|
except ValueError:
|
|
print('address/netmask is invalid: %s' % sys.argv[1])
|
|
except:
|
|
print('Usage : %s ip' % sys.argv[0])
|
|
|
|
return False
|
|
|
|
|
|
def is_valid_hostname(hostname):
|
|
if len(hostname) > 255:
|
|
return False
|
|
if hostname[-1] == ".":
|
|
hostname = hostname[:-1] # strip exactly one dot from the right, if present
|
|
allowed = re.compile("(?!-)[A-Z\d-]{1,63}(?<!-)$", re.IGNORECASE)
|
|
return all(allowed.match(x) for x in hostname.split("."))
|