Skip to main content

ipv4Address

ipv4Address(num: Number) : IpAddress

Constructs an IPv4 address from an integer in the range 0 to (2 ^ 32) - 1. For example,

  1. ipv4Address(0) denotes 0.0.0.0
  2. ipv4Address(4) denotes 0.0.0.4
  3. ipv4Address(1234) denotes 0.0.4.210
  4. ipv4Address(123456789) denotes 7.91.205.21
  5. ipv4Address((2 ^ 32) - 1) denotes 255.255.255.255

For numbers outside the range 0..2^32-1, ipv4Address throws an error.

Whereas ipv4Address constructs IP addresses from integers, there is the ipAddress method to construct IP addresses from strings. Moreover, we can construct integers from IP addresses using toNumber.

Properties

The ipv4Address function and the toNumber are inverses: toNumber(ip) == num is true exactly when ip == ipv4Address(num) is true, for ip an IPv4 address and num an integer in 0..2^32-1. For example:

  • ipv4Address(toNumber(ipAddress("1.2.3.4"))) == ipAddress("1.2.3.4")
  • toNumber(ipv4Address(1234))) == 1234

See also

Types

Functions