Skip to main content

IP Addresses

IP addresses can be written like this: ipAddress("1.2.3.4") for IPv4 or ipAddress("2001:0db8:85a3:0000:0000:8a2e:0370:7334") for IPv6. Such values have type IpAddress.

If ip has type IpAddress, then it can be inverted via - like this: -ip. For example, -ipAddress("0.0.0.255") is an expression of the IP address 255.255.255.0.

In addition, the following functions work on IP addresses:

  • toNumber(ipv4Address): The numeric value corresponding to an IPv4 address. For example, toNumber(ipAddress("0.0.1.2")) is 258. Note that this can only be applied to IPv4 addresses.

  • ipv4Address(integer): The IPv4 address corresponding to a given integer in the range0 to 2 ^ 32 - 1. For example, ipv4Address(0) denotes 0.0.0.0 and ipv4Address(1234) denotes 0.0.4.210.

  • isIPv4(ipAddress): Tests whether ipAddress is an IPv4 address. For example, isIPv4(ipAddress("1.2.3.4")) returns true and isIPv4(ipAddress("2001:0db8:85a3:0000:0000:8a2e:0370:7334") returns false.

  • isIPv6(ipAddress): Tests whether ipAddress is an IPv6 address. For example, isIPv6(ipAddress("2001:0db8:85a3:0000:0000:8a2e:0370:7334") returns true and isIPv6(ipAddress("1.2.3.4")) returns false.

  • fromTo(ipAddress, ipAddress): List of IP addresses between two ipAddress.