### ip-address

`5.9.0`
Need help reading this?

### Address4

lib/ipv4.js

Represents an IPv4 address

new Address4(address: string)
Parameters
address `(string)` An IPv4 address string
Static Members
▸ fromHex(hex)
lib/ipv4.js

Converts a hex string to an IPv4 address object

fromHex(hex: string): Address4
Parameters
hex `(string)` a hex string to convert
Returns
`Address4`:
▸ fromInteger(integer)
lib/ipv4.js

Converts an integer into a IPv4 address object

fromInteger(integer: integer): Address4
Parameters
integer `(integer)` a number to convert
Returns
`Address4`:
▸ fromBigInteger(bigInteger)
lib/ipv4.js

Converts a BigInteger to a v4 address object

fromBigInteger(bigInteger: BigInteger): Address4
Parameters
bigInteger `(BigInteger)` a BigInteger to convert
Returns
`Address4`:
Instance Members
▸ isValid()
lib/ipv4.js

Return true if the address is valid

isValid(): Boolean
Returns
`Boolean`:
▸ correctForm()
lib/ipv4.js

Returns the correct form of an address

correctForm(): String
Returns
`String`:
▸ isCorrect
lib/ipv4.js

Returns true if the address is correct, false otherwise

isCorrect
Returns
`Boolean`:
▸ toHex()
lib/ipv4.js

Converts an IPv4 address object to a hex string

toHex(): String
Returns
`String`:
▸ toArray()
lib/ipv4.js

Converts an IPv4 address object to an array of bytes

toArray(): Array
Returns
`Array`:
▸ toGroup6()
lib/ipv4.js

Converts an IPv4 address object to an IPv6 address group

toGroup6(): String
Returns
`String`:
▸ bigInteger()
lib/ipv4.js

Returns the address as a BigInteger

bigInteger(): BigInteger
Returns
`BigInteger`:
▸ _startAddress()
lib/ipv4.js

Helper function getting start address.

_startAddress(): BigInteger
Returns
`BigInteger`:
▸ startAddress()
lib/ipv4.js

The first address in the range given by this address' subnet. Often referred to as the Network Address.

startAddress(): Address4
Returns
`Address4`:
▸ startAddressExclusive()
lib/ipv4.js

The first host address in the range given by this address's subnet ie the first address after the Network Address

startAddressExclusive(): Address4
Returns
`Address4`:
▸ _endAddress()
lib/ipv4.js

Helper function getting end address.

_endAddress(): BigInteger
Returns
`BigInteger`:
▸ endAddress()
lib/ipv4.js

The last address in the range given by this address' subnet Often referred to as the Broadcast

endAddress(): Address4
Returns
`Address4`:
▸ endAddressExclusive()
lib/ipv4.js

The last host address in the range given by this address's subnet ie the last address prior to the Broadcast Address

endAddressExclusive(): Address4
Returns
`Address4`:
▸ mask(optionalMask)
lib/ipv4.js

Returns the first n bits of the address, defaulting to the subnet mask

mask(optionalMask: any): String
Parameters
optionalMask `(any)`
Returns
`String`:
▸ getBitsBase2(start, end)
lib/ipv4.js

Returns the bits in the given range as a base-2 string

getBitsBase2(start: any, end: any): string
Parameters
start `(any)`
end `(any)`
Returns
`string`:
▸ isInSubnet
lib/ipv4.js

Returns true if the given address is in the subnet of the current address

isInSubnet
Returns
`boolean`:
▸ binaryZeroPad()
lib/ipv4.js

Returns a zero-padded base-2 string representation of the address

binaryZeroPad(): string
Returns
`string`:

### Address6

lib/ipv6.js

Represents an IPv6 address

new Address6(address: string, groups: number)
Parameters
address `(string)` An IPv6 address string
groups `(number = `8`)` How many octets to parse
Example

    var address = new Address6('2001::/32');

Static Members
▸ fromBigInteger(bigInteger)
lib/ipv6.js

Convert a BigInteger to a v6 address object

fromBigInteger(bigInteger: BigInteger): Address6
Parameters
bigInteger `(BigInteger)` a BigInteger to convert
Returns
`Address6`:
Example

    var bigInteger = new BigInteger('1000000000000');
    var address = Address6.fromBigInteger(bigInteger);
    address.correctForm(); // '::e8:d4a5:1000'

▸ fromURL(url)
lib/ipv6.js

Convert a URL (with optional port number) to an address object

fromURL(url: string): Address6
Parameters
url `(string)` a URL with optional port number
Returns
`Address6`:
Example

    var addressAndPort = Address6.fromURL('http://[ffff::]:8080/foo/');
    addressAndPort.address.correctForm(); // 'ffff::'
    addressAndPort.port; // 8080

▸ fromAddress4(address4, address)
lib/ipv6.js

Create an IPv6-mapped address given an IPv4 address

fromAddress4(address4: any, address: string): Address6
Parameters
address4 `(any)`
address `(string)` An IPv4 address string
Returns
`Address6`:
Example

    var address = Address6.fromAddress4('192.168.0.1');
    address.correctForm(); // '::ffff:c0a8:1'
    address.to4in6(); // '::ffff:192.168.0.1'

▸ fromArpa(arpaFormAddress)
lib/ipv6.js

Return an address from ip6.arpa form

fromArpa(arpaFormAddress: string): Adress6
Parameters
arpaFormAddress `(string)` an 'ip6.arpa' form address
Returns
`Adress6`:
Example

    var address = Address6.fromArpa(e.f.f.f.3.c.2.6.f.f.f.e.6.6.8.e.1.0.6.7.9.4.e.c.0.0.0.0.1.0.0.2.ip6.arpa.)
    address.correctForm(); // '2001:0:ce49:7601:e866:efff:62c3:fffe'

▸ fromByteArray(bytes)
lib/ipv6.js

Convert a byte array to an Address6 object

fromByteArray(bytes: any): Address6
Parameters
bytes `(any)`
Returns
`Address6`:
▸ fromUnsignedByteArray(bytes)
lib/ipv6.js

Convert an unsigned byte array to an Address6 object

fromUnsignedByteArray(bytes: any): Address6
Parameters
bytes `(any)`
Returns
`Address6`:
▸ SCOPES
lib/v6/constants.js

Represents IPv6 address scopes

SCOPES
▸ TYPES
lib/v6/constants.js

Represents IPv6 address types

TYPES
▸ RE_BAD_CHARACTERS
lib/v6/constants.js

A regular expression that matches bad characters in an IPv6 address

RE_BAD_CHARACTERS
▸ RE_BAD_ADDRESS
lib/v6/constants.js

A regular expression that matches an incorrect IPv6 address

RE_BAD_ADDRESS
▸ RE_SUBNET_STRING
lib/v6/constants.js

A regular expression that matches an IPv6 subnet

RE_SUBNET_STRING
▸ RE_ZONE_STRING
lib/v6/constants.js

A regular expression that matches an IPv6 zone

RE_ZONE_STRING
Instance Members
▸ microsoftTranscription()
lib/ipv6.js

Return the Microsoft UNC transcription of the address

microsoftTranscription(): String
Returns
`String`: the Microsoft UNC transcription of the address
▸ mask(optionalMask, mask)
lib/ipv6.js

Return the first n bits of the address, defaulting to the subnet mask

mask(optionalMask: any, mask: number): String
Parameters
optionalMask `(any)`
mask `(number = `subnet`)` the number of bits to mask
Returns
`String`: the first n bits of the address as a string
▸ possibleSubnets(optionalSubnetSize, size)
lib/ipv6.js

Return the number of possible subnets of a given size in the address

possibleSubnets(optionalSubnetSize: any, size: number): String
Parameters
optionalSubnetSize `(any)`
size `(number = `128`)` the subnet size
Returns
`String`:
▸ _startAddress()
lib/ipv6.js

Helper function getting start address.

_startAddress(): BigInteger
Returns
`BigInteger`:
▸ startAddress()
lib/ipv6.js

The first address in the range given by this address' subnet Often referred to as the Network Address.

startAddress(): Address6
Returns
`Address6`:
▸ startAddressExclusive()
lib/ipv6.js

The first host address in the range given by this address's subnet ie the first address after the Network Address

startAddressExclusive(): Address6
Returns
`Address6`:
▸ _endAddress()
lib/ipv6.js

Helper function getting end address.

_endAddress(): BigInteger
Returns
`BigInteger`:
▸ endAddress()
lib/ipv6.js

The last address in the range given by this address' subnet Often referred to as the Broadcast

endAddress(): Address6
Returns
`Address6`:
▸ endAddressExclusive()
lib/ipv6.js

The last host address in the range given by this address's subnet ie the last address prior to the Broadcast Address

endAddressExclusive(): Address6
Returns
`Address6`:
▸ getScope()
lib/ipv6.js

Return the scope of the address

getScope(): String
Returns
`String`:
▸ getType()
lib/ipv6.js

Return the type of the address

getType(): String
Returns
`String`:
▸ getBits(start, end)
lib/ipv6.js

Return the bits in the given range as a BigInteger

getBits(start: any, end: any): BigInteger
Parameters
start `(any)`
end `(any)`
Returns
`BigInteger`:
▸ getBitsBase2(start, end)
lib/ipv6.js

Return the bits in the given range as a base-2 string

getBitsBase2(start: any, end: any): String
Parameters
start `(any)`
end `(any)`
Returns
`String`:
▸ getBitsBase16(start, end)
lib/ipv6.js

Return the bits in the given range as a base-16 string

getBitsBase16(start: any, end: any): String
Parameters
start `(any)`
end `(any)`
Returns
`String`:
▸ getBitsPastSubnet()
lib/ipv6.js

Return the bits that are set past the subnet mask length

getBitsPastSubnet(): String
Returns
`String`:
▸ reverseForm(options)
lib/ipv6.js

Return the reversed ip6.arpa form of the address

reverseForm(options: Object): String
Parameters
options `(Object)`

Name | Description
--- | ---
options.omitSuffix `boolean` | omit the "ip6.arpa" suffix

Returns
`String`:
▸ correctForm()
lib/ipv6.js

Return the correct form of the address

correctForm(): String
Returns
`String`:
▸ binaryZeroPad()
lib/ipv6.js

Return a zero-padded base-2 string representation of the address

binaryZeroPad(): String
Returns
`String`:
Example

    var address = new Address6('2001:4860:4001:803::1011');
    address.binaryZeroPad();
    // '0010000000000001010010000110000001000000000000010000100000000011
    //  0000000000000000000000000000000000000000000000000001000000010001'

▸ canonicalForm()
lib/ipv6.js

Return the canonical form of the address

canonicalForm(): String
Returns
`String`:
▸ decimal()
lib/ipv6.js

Return the decimal form of the address

decimal(): String
Returns
`String`:
▸ bigInteger()
lib/ipv6.js

Return the address as a BigInteger

bigInteger(): BigInteger
Returns
`BigInteger`:
▸ to4()
lib/ipv6.js

Return the last two groups of this address as an IPv4 address string

to4(): String
Returns
`String`:
Example

    var address = new Address6('2001:4860:4001::1825:bf11');
    address.to4(); // '24.37.191.17'

▸ to4in6()
lib/ipv6.js

Return the v4-in-v6 form of the address

to4in6(): String
Returns
`String`:
▸ inspectTeredo()
lib/ipv6.js

Return an object containing the Teredo properties of the address

inspectTeredo(): Object
Returns
`Object`:
▸ inspect6to4()
lib/ipv6.js

Return an object containing the 6to4 properties of the address

inspect6to4(): Object
Returns
`Object`:
▸ to6to4()
lib/ipv6.js

Return a v6 6to4 address from a v6 v4inv6 address

to6to4(): Address6
Returns
`Address6`:
▸ toByteArray()
lib/ipv6.js

Return a byte array

toByteArray(): Array
Returns
`Array`:
▸ toUnsignedByteArray()
lib/ipv6.js

Return an unsigned byte array

toUnsignedByteArray(): Array
Returns
`Array`:
▸ isValid()
lib/v6/attributes.js

Returns true if the address is valid, false otherwise

isValid(): boolean
Returns
`boolean`:
▸ isInSubnet
lib/v6/attributes.js

Returns true if the given address is in the subnet of the current address

isInSubnet
Returns
`boolean`:
▸ isCorrect
lib/v6/attributes.js

Returns true if the address is correct, false otherwise

isCorrect
Returns
`boolean`:
▸ isCanonical
lib/v6/attributes.js

Returns true if the address is in the canonical form, false otherwise

isCanonical
Returns
`boolean`:
▸ isLinkLocal
lib/v6/attributes.js

Returns true if the address is a link local address, false otherwise

isLinkLocal
Returns
`boolean`:
▸ isMulticast
lib/v6/attributes.js

Returns true if the address is a multicast address, false otherwise

isMulticast
Returns
`boolean`:
▸ is4
lib/v6/attributes.js

Returns true if the address is a v4-in-v6 address, false otherwise

is4
Returns
`boolean`:
▸ isTeredo
lib/v6/attributes.js

Returns true if the address is a Teredo address, false otherwise

isTeredo
Returns
`boolean`:
▸ is6to4
lib/v6/attributes.js

Returns true if the address is a 6to4 address, false otherwise

is6to4
Returns
`boolean`:
▸ isLoopback
lib/v6/attributes.js

Returns true if the address is a loopback address, false otherwise

isLoopback
Returns
`boolean`:
▸ regularExpressionString(optionalSubString)
lib/v6/regular-expressions.js

Generate a regular expression string that can be used to find or validate all variations of this address

regularExpressionString(optionalSubString: string): string
Parameters
optionalSubString `(string)`
Returns
`string`:
▸ regularExpression(optionalSubstring, optionalSubString)
lib/v6/regular-expressions.js

Generate a regular expression that can be used to find or validate all variations of this address.

regularExpression(optionalSubstring: any, optionalSubString: string): RegExp
Parameters
optionalSubstring `(any)`
optionalSubString `(string)`
Returns
`RegExp`:

### href

lib/v6/html.js
href(optionalPort: any): String
Parameters
optionalPort `(any)`
Returns
`String`: the address in link form with a default port of 80

### link

lib/v6/html.js
link(options: any): String
Parameters
options `(any)`
Returns
`String`: a link suitable for conveying the address via a URL hash

### group

lib/v6/html.js

Groups an address

group(): String
Returns
`String`:

### spanAllZeroes

lib/v6/helpers.js
spanAllZeroes
Returns
`String`: the string with all zeroes contained in a

### spanAll

lib/v6/helpers.js
spanAll(s: any, optionalOffset: any): String
Parameters
s `(any)`
optionalOffset `(any)`
Returns
`String`: the string with each character contained in a

### spanLeadingZeroes

lib/v6/helpers.js
spanLeadingZeroes(address: any): String
Parameters
address `(any)`
Returns
`String`: the string with leading zeroes contained in a

### simpleGroup

lib/v6/helpers.js

Groups an address

simpleGroup(addressString: any, offset: any): String
Parameters
addressString `(any)`
offset `(any)`
Returns
`String`: a grouped address