Function hextoip

  • convert a hexadecimal string to IP addresss

    Parameters

    • s: string

      hexadecimal string of IP address

    Returns string

    IP address string

    Description

    This function converts a hexadecimal string of IPv4 or IPv6 address to IPv4 or IPv6 address string. If byte length is not 4 nor 16, this returns a hexadecimal string without conversion.

    Example

    hextoip("c0a80101") -> "192.168.1.1"
    hextoip("871020010db8000000000000000000000004") -> "2001:db8::4"
    hextoip("c0a80100ffffff00") -> "192.168.1.0/24"
    hextoip("c0a801010203") -> "c0a801010203" // wrong 6 bytes
    hextoip("zzz")) -> raise exception because of not hexadecimal