IPv4 Operations
This document outlines the IPv4 data type operators.
They are useful when dealing with IP addresses.
The IP addresses can be in the range of 0.0.0.1
- 255.255.255.255
.
The address: 0.0.0.0
is interpreted as null.
The following operators support string
type arguments to permit the passing of netmasks:
- << Strict IP address contained by
- <<= IP address contained by or equal
- rnd_ipv4(string, int)
- netmask()
See IPv4 SQL functions for more guidance around IPv4 beyond operators.
#
Operators#
< Less thanTakes two IPv4 arguments.
Returns a boolean.
#
ExampleUse case: testing to see if one IP address is less than another.
#
<= Less than or equalTakes two IPv4 arguments.
Returns a boolean.
#
ExampleUse case: testing to see if one IP address is less than or equal to another.
#
> Greater thanTakes two IPv4 arguments.
Returns a boolean.
#
ExampleUse case: testing to see if one IP address is greater than another.
#
>= Greater than or equalTakes two IPv4 arguments.
Returns a boolean.
#
ExampleUse case: testing to see if one IP address is greater than or equal to another.
#
= EqualsTakes two IPv4 arguments.
Returns a boolean.
#
ExampleUse case: testing to see if one IP address is equal to another.
#
!= Does not equalTakes two IPv4 arguments.
Returns a boolean.
#
ExampleUse case: testing to see if one IP address is not equal to another.
#
<< Strict IP address contained byTakes one IPv4 argument and one string argument.
The string argument can accept IPv4 addresses with a subnet mask, the IPv4 argument cannot.
Returns a boolean.
#
ExampleUse case: searching ip addresses by subnet
#
<<= IP address contained by or equalTakes one IPv4 argument and one string argument
The string argument can accept IPv4 addresses with a subnet mask, the IPv4 argument cannot.
Returns a boolean.
#
ExampleUse case: searching ip addresses by subnet
#
& Bitwise ANDTakes two IPv4 arguments.
Returns an IPv4 address.
#
ExampleUse case: separating an ip address into its network and host portions
#
~ Bitewise NOTTakes one IPv4 argument.
Returns an IPv4 address.
#
ExampleUse case: computing broadcast address' bitmask from a netmask
#
| Bitwise ORTakes two IPv4 arguments.
Returns an IPv4 address.
#
ExampleUse case: computing an ip address' broadcast address
#
+ Add offset to an IP addressTakes one IPv4 argument and one integer argument.
Returns an IPv4 address.
#
ExampleUse case: altering an ip address
#
- Subtract offset from IP addressTakes one IPv4 argument and one integer argument.
Returns an IPv4 address.
#
Example#
- Difference between two IP addressesTakes two IPv4 arguments.
Returns a long.
#
ExampleUse case: calculating the range of unique addresses between two ip addresses
#
Return netmask - netmask(string)Takes a string
IPv4 argument as either:
- ipv4 address with a netmask
22.59.138.9/8
- subnet with netmask:
2.2/16
Returns an IPv4 addresses' netmask (255.0.0.0
) in IPv4 format.
#
ExampleUse case: Obtaining the broadcast bitmask for an ip address via performing bitwise NOT on the netmask.
Apply a bitwise OR to this result to obtain the broadcast address of an ip address.
#
Random address generator - rnd_ipv4()Random address generator for a single address.
Returns a single IPv4 address.
Useful for testing.
#
Example#
Random address range generator - rnd_ipv4(string, int)Generates a random ip address within the bounds of a given subnet.
The integer argument dictates how many null values will be generated.
Returns an IPv4 address within specified range.
#
Example#
LimitationsIPv4 column types cannot be created via InfluxDB Line Protocol as the protocol lacks support for IPv4. As a result, the server cannot distinguish between string and IPv4 data. However, InfluxDB Line Protocol can still insert string data into a pre-existing column of type IPv4.