def __init__(self, address, netmask, gateway): _IP.__init__(self, address, netmask, gateway) if netmask[0] != "/": netmask = "/%s" % netmask self.netmask = ip("::%s" % netmask)
def check_db_host(_string:str, _fix:bool=True): """Function to check a string if it is a legitimate db host. Example: Correct example "123.123.123.123". Correct example "127.0.0.1". Correct example "255.255.255.255". Correct example "http://localhost". Correct example "https://localhost". Wrong example "-1.0.0.0". Wrong example "127. 0.0.1". Wrong example "127. 0. 0. 1". Wrong example "127. 0. 0.1". Wrong example "127. 0.0.1". Wrong example "2555.255.255.255". Wrong example "http://localhost/" can be fixed into "http://localhost" with `_fix=True`. Wrong example "https://localhost/" can be fixed into "https://localhost" with `_fix=True`. """ localhost = [ "http://localhost", "https://localhost", "localhost" ] if _fix and (_string[-1:] == "/" or _string[-1:] == "\\"): _string = _string[:-1] for i in localhost: if i == _string: return True try: ip(_string) except ValueError: return False return True
def __init__(self, address, netmask, gateway): self.address = ip(address) self.gateway = ip(gateway)