Represents an v4 or v6 Internet Protocol (IP) address.

Members

Array

buffer

Immutable buffer that represents the IP address

Number

length

Returns the length of the underlying buffer

Number

version

Returns the Ip version (4 or 6)

Constructor

new

InetAddress

(Buffer buffer)

Creates a new instance of InetAddress

Parameters:
Name Type Description
buffer Buffer

Methods

equals

(InetAddress other)

Compares 2 addresses and returns true if the underlying bytes are the same

Parameters:
Name Type Description
other InetAddress
Returns:
Type Description
Boolean

InetAddress.fromString

(String value)

Parses the string representation and returns an Ip address

Static
This function is static
Parameters:
Name Type Description
value String

getBuffer

()

Returns the underlying buffer

Returns:
Type Description
Buffer

inspect

()

Provide the name of the constructor and the string representation

Returns:
Type Description
string

toJSON

()

Returns the string representation. Method used by the native JSON.stringify() to serialize this instance.

toString

([String encoding])

Returns the string representation of the IP address.

For v4 IP addresses, a string in the form of d.d.d.d is returned.

For v6 IP addresses, a string in the form of x:x:x:x:x:x:x:x is returned, where the ‘x’s are the hexadecimal values of the eight 16-bit pieces of the address, according to rfc5952. In cases where there is more than one field of only zeros, it can be shortened. For example, 2001:0db8:0:0:0:1:0:1 will be expressed as 2001:0db8::1:0:1.

Parameters:
Name Type Description
encoding optional String
Returns:
Type Description
String