コード例 #1
0
ファイル: ipnetwork.py プロジェクト: vijayekm/openr
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
コード例 #2
0
ファイル: ipnetwork.py プロジェクト: Warrelis/openr
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)