IP functions
Learn how to use and combine different ip functions in APL
IP functions
Function Name | Description |
---|---|
format_ipv4() | Parses input with a netmask and returns string representing IPv4 address. |
parse_ipv4() | Converts input to long (signed 64-bit) number representation. |
parse_ipv4_mask() | Converts input string and IP-prefix mask to long (signed 64-bit) number representation. |
ipv4_is_in_range() | Checks if IPv4 string address is in IPv4-prefix notation range. |
ipv4_is_private() | Checks if IPv4 string address belongs to a set of private network IPs. |
ipv4_netmask_suffix() | Returns the value of the IPv4 netmask suffix from IPv4 string address. |
geo_info_from_ip_address() | Extracts geographical, geolocation, and network information from IP addresses. It supports both IPv4 and IPv6 addresses. |
IP-prefix notation
IP addresses can be defined with IP-prefix notation
using a slash (/) character. The IP address to the LEFT of the slash (/*) is the base IP address. The number (1 to 32) to the RIGHT of the slash (/) is the number of contiguous 1 bit in the netmask.
For example, 192.168.2.0/24
will have an associated net/subnetmask containing 24 contiguous bits or 255.255.255.0
in dotted decimal format.
format_ipv4()
Parses input with a netmask and returns string representing IPv4 address.
Arguments
- Expr(IP): A string or number representation of the IPv4 address.
Returns
If conversion is successful, the result will be a string representing IPv4 address. If conversion isn’t successful, the result will be an empty string.
Example
- Result
parse_ipv4()
Converts IPv4 string to long (signed 64-bit) number representation.
Arguments
- Expr: String expression representing IPv4 that will be converted to long. String may include net-mask using IP-prefix notation.
Returns
If conversion is successful, the result will be a long number. If conversion isn’t successful, the result will be null.
Example
- Result
parse_ipv4_mask()
Converts the input string of IPv4 and netmask to long number representation (signed 64-bit).
Arguments
Expr:
A string representation of the IPv4 address that will be converted to long.PrefixMask:
An integer from 0 to 32 representing the number of most-significant bits that are taken into account.
Returns
If conversion is successful, the result will be a long number. If conversion isn’t successful, the result will be null.
Example
- Result
ipv4_is_in_range()
Checks if IPv4 string address is in IPv4-prefix notation range.
Arguments
- Ipv4Address: A string expression representing an IPv4 address.
- Ipv4Range: A string expression representing an IPv4 range using IP-prefix notation.
Returns
true
: If the long representation of the first IPv4 string argument is in range of the second IPv4 string argument.false
: Otherwise.null
: If conversion for one of the two IPv4 strings wasn’t successful.
Examples
- Result
- Result
- Result
ipv4_is_private()
Checks if IPv4 string address belongs to a set of private network IPs.
Private IPv4 addresses
The private IPv4 addresses reserved for private networks by the Internet Assigned Numbers Authority (IANA) are:
IP address range | Number of addresses | Largest CIDR block (subnet mask) |
---|---|---|
10.0.0.0 – 10.255.255.255 | 16777216 | 10.0.0.0/8 (255.0.0.0) |
172.16.0.0 – 172.31.255.255 | 1048576 | 172.16.0.0/12 (255.240.0.0) |
192.168.0.0 – 192.168.255.255 | 65536 | 192.168.0.0/16 (255.255.0.0) |
Arguments
- Expr: A string expression representing an IPv4 address. IPv4 strings can be masked using IP-prefix notation.
Returns
true
: If the IPv4 address belongs to any of the private network ranges.false
: Otherwise.null
: If parsing of the input as IPv4 address string wasn’t successful.
Example
- Result
- Result
ipv4_netmask_suffix()
Returns the value of the IPv4 netmask suffix from IPv4 string address.
Arguments
Expr: A string expression representing an IPv4 address. IPv4 strings can be masked using IP-prefix notation.
Returns
-
The value of the netmask suffix the IPv4 address. If suffix is not present in the input, a value of 32 (full netmask suffix) is returned.
-
null: If parsing of the input as IPv4 address string wasn’t successful.
Example
- Result
- Result
geo_info_from_ip_address()
Extracts geographical, geolocation, and network information from IP addresses. It supports both IPv4 and IPv6 addresses.
Arguments
Name | Type | Required | Description |
---|---|---|---|
ipAddress | String | Yes | The IP address to extract information from. Can be IPv4 or IPv6 |
Returns
A dynamic object containing the information on the IP address’s whereabouts (if the information is available). The object contains the following fields:
Name | Type | Description |
---|---|---|
country | string | Country name |
state | string | State (subdivision) name |
city | string | City name |
latitude | real | Latitude coordinate |
longitude | real | Longitude coordinate |
country_iso | string | ISO code of the country |
time_zone | string | Time zone in which the IP address is located |
Examples
IPv4 Examples
Extracting geolocation information from IPv4 address
Projecting geolocation information from IPv4 address
Filtering geolocation information from IPv4 address
Grouping geolocation information from IPv4 address
IPv6 Examples
Extracting geolocation information from IPv6 address
Projecting geolocation information from IPv6 address
Filtering geolocation information from IPv6 address
Grouping geolocation information from IPv6 address
Was this page helpful?