def ip_str_to_addr(addr_str: str, if_index: str = None) -> network_types.BinaryAddress: """ :param addr_str: ip address in string representation :returns: thrift struct BinaryAddress :rtype: network_types.BinaryAddress """ # Try v4 try: addr = socket.inet_pton(socket.AF_INET, addr_str) binary_address = network_types.BinaryAddress(addr=addr) if if_index: binary_address.ifName = if_index return binary_address except socket.error: pass # Try v6 addr = socket.inet_pton(socket.AF_INET6, addr_str) binary_address = network_types.BinaryAddress(addr=addr) if if_index: binary_address.ifName = if_index return binary_address
def ip_str_to_addr(addr_str): """ :param addr_str: ip address in string representation :returns: thrift struct BinaryAddress :rtype: network_types.BinaryAddress """ # Try v4 try: addr = socket.inet_pton(socket.AF_INET, addr_str) return network_types.BinaryAddress(addr=addr) except socket.error: pass # Try v6 addr = socket.inet_pton(socket.AF_INET6, addr_str) return network_types.BinaryAddress(addr=addr)