ip2long()

The ip2long() function converts an IPv4 address to an unsigned 64-bit integer.

Syntax

ip2long(IP)

Parameters

IP
The IPv4 address to convert. Accepts a string or IP address type. If the value contains CIDR notation (for example, 192.0.2.0/24), the network address portion (before the slash) is used for conversion.

Description

The ip2long() function converts an IPv4 address to an unsigned 64-bit integer (long type). Unlike ip2int(), it returns all IPv4 addresses as positive integers.

Returns null if the IP address format is invalid. Returns null if IP is null.

Error codes

N/A

Usage examples

To prepare the WEB_APACHE_SAMPLE table used in these examples, refer to Preparing sample data.

  1. Convert the source IP address to a 64-bit integer.

    table limit=5 WEB_APACHE_SAMPLE | eval result = ip2long(src_ip)
    | fields src_ip, result
    
  2. Convert a string with CIDR notation.

    json "{}" | eval n = ip2long("192.0.2.0/24")
    | # n: 402653184
    
  3. NULL input

    json "{}" | eval n = ip2long(null)
    | # n: null
    

Compatibility

The ip2long() function has been available since before Sonar 4.0.