def ip2bytes(ipaddress): ipadd = ipaddress.split('.') assert len(ipadd) == 4 ipadd = list(map(int, ipadd)) ipNum = int.from_bytes(ipadd, 'big') return ipNum.to_bytes(4, 'big')
def __init__(self, ipaddress): ip, mask = ipaddress.split("/") self._check_ip(ip) self._check_mask(mask) self.ip, self.mask = ip, int(mask)
def returnBinaryIpAddress(ipaddress): ip = ipaddress.split(".") #binaryIp = '' #for ele in ip: # binaryIp += "{0:08b}".format(int(ele)) return [int(x) for x in ip]