ip2int()
The ip2int() function converts an IPv4 address to a signed 32-bit integer.
Syntax
ip2int(IP)
Parameters
IP- The IPv4 address to convert. Accepts a string or IP address type. If the string contains a slash (
/), the text after the first slash is parsed as an IP address.
Description
The ip2int() function converts an IPv4 address to a signed 32-bit integer (integer type). IP addresses with a first octet of 128 or greater exceed the 32-bit signed integer range and are returned as negative numbers.
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.
-
Convert the source IP address to a 32-bit integer.
table limit=5 WEB_APACHE_SAMPLE | eval result = ip2int(src_ip) | fields src_ip, result -
Convert a string that starts with a slash.
json "{}" | eval n = ip2int("/192.0.2.1") | # n: -1073741311 -
NULL input
json "{}" | eval n = ip2int(null) | # n: null
Compatibility
The ip2int() function has been available since before Sonar 4.0.