ip-address

  • Version 8.1.0
  • Published
  • 230 kB
  • 2 dependencies
  • MIT license

Install

npm i ip-address
yarn add ip-address
pnpm add ip-address

Overview

A library for parsing IPv4 and IPv6 IP addresses in node and the browser.

Index

Variables

variable v6

const v6: { helpers: typeof helpers };

    Classes

    class Address4

    class Address4 {}
    • Represents an IPv4 address Address4

      Parameter address

      An IPv4 address string

    constructor

    constructor(address: string);

      property address

      address: string;

        property addressMinusSuffix

        addressMinusSuffix?: string;

          property groups

          groups: number;

            property isCorrect

            isCorrect: (this: import('./ipv6').Address6 | Address4) => boolean;
            • Returns true if the address is correct, false otherwise Address4

              Returns

              {Boolean}

            property isInSubnet

            isInSubnet: (this: Address4 | Address6, address: Address4 | Address6) => boolean;
            • Returns true if the given address is in the subnet of the current address Address4

              Returns

              {boolean}

            property parsedAddress

            parsedAddress: string[];

              property parsedSubnet

              parsedSubnet: string;

                property subnet

                subnet: string;

                  property subnetMask

                  subnetMask: number;

                    property v4

                    v4: boolean;

                      method bigInteger

                      bigInteger: () => any;
                      • Returns the address as a BigInteger Address4

                        Returns

                        {BigInteger}

                      method binaryZeroPad

                      binaryZeroPad: () => string;
                      • Returns a zero-padded base-2 string representation of the address Address4

                        Returns

                        {string}

                      method correctForm

                      correctForm: () => string;
                      • Returns the correct form of an address Address4

                        Returns

                        {String}

                      method endAddress

                      endAddress: () => Address4;
                      • The last address in the range given by this address' subnet Often referred to as the Broadcast Address4

                        Returns

                        {Address4}

                      method endAddressExclusive

                      endAddressExclusive: () => Address4;
                      • The last host address in the range given by this address's subnet ie the last address prior to the Broadcast Address Address4

                        Returns

                        {Address4}

                      method fromArpa

                      static fromArpa: (arpaFormAddress: string) => Address4;
                      • Return an address from in-addr.arpa form Address4

                        Parameter arpaFormAddress

                        an 'in-addr.arpa' form ipv4 address

                        Returns

                        {Adress4}

                        Example 1

                        var address = Address4.fromArpa(42.2.0.192.in-addr.arpa.) address.correctForm(); // '192.0.2.42'

                      method fromBigInteger

                      static fromBigInteger: (bigInteger: any) => Address4;
                      • Converts a BigInteger to a v4 address object Address4

                        Parameter bigInteger

                        a BigInteger to convert

                        Returns

                        {Address4}

                      method fromHex

                      static fromHex: (hex: string) => Address4;
                      • Converts a hex string to an IPv4 address object Address4

                        Parameter hex

                        a hex string to convert

                        Returns

                        {Address4}

                      method fromInteger

                      static fromInteger: (integer: number) => Address4;
                      • Converts an integer into a IPv4 address object Address4

                        Parameter integer

                        a number to convert

                        Returns

                        {Address4}

                      method getBitsBase2

                      getBitsBase2: (start: number, end: number) => string;
                      • Returns the bits in the given range as a base-2 string Address4

                        Returns

                        {string}

                      method groupForV6

                      groupForV6: () => string;
                      • Groups an IPv4 address for inclusion at the end of an IPv6 address

                        Returns

                        {String}

                      method isMulticast

                      isMulticast: () => boolean;
                      • Returns true if the given address is a multicast address Address4

                        Returns

                        {boolean}

                      method isValid

                      static isValid: (address: string) => boolean;

                        method mask

                        mask: (mask?: number) => string;
                        • Returns the first n bits of the address, defaulting to the subnet mask Address4

                          Returns

                          {String}

                        method parse

                        parse: (address: string) => string[];

                          method reverseForm

                          reverseForm: (options?: common.ReverseFormOptions) => string;
                          • Return the reversed ip6.arpa form of the address Address4

                            Parameter options

                            Parameter

                            {boolean} options.omitSuffix - omit the "in-addr.arpa" suffix

                            Returns

                            {String}

                          method startAddress

                          startAddress: () => Address4;
                          • The first address in the range given by this address' subnet. Often referred to as the Network Address. Address4

                            Returns

                            {Address4}

                          method startAddressExclusive

                          startAddressExclusive: () => Address4;
                          • The first host address in the range given by this address's subnet ie the first address after the Network Address Address4

                            Returns

                            {Address4}

                          method toArray

                          toArray: () => number[];
                          • Converts an IPv4 address object to an array of bytes Address4

                            Returns

                            {Array}

                          method toGroup6

                          toGroup6: () => string;
                          • Converts an IPv4 address object to an IPv6 address group Address4

                            Returns

                            {String}

                          method toHex

                          toHex: () => string;
                          • Converts an IPv4 address object to a hex string Address4

                            Returns

                            {String}

                          class Address6

                          class Address6 {}
                          • Represents an IPv6 address Address6

                            Parameter address

                            An IPv6 address string

                            Parameter groups

                            How many octets to parse

                            Example 1

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

                          constructor

                          constructor(address: string, optionalGroups?: number);

                            property address

                            address: string;

                              property address4

                              address4?: Address4;

                                property addressMinusSuffix

                                addressMinusSuffix: string;

                                  property elidedGroups

                                  elidedGroups?: number;

                                    property elisionBegin

                                    elisionBegin?: number;

                                      property elisionEnd

                                      elisionEnd?: number;

                                        property groups

                                        groups: number;

                                          property isCorrect

                                          isCorrect: (this: Address6 | Address4) => boolean;
                                          • Returns true if the address is correct, false otherwise Address6

                                            Returns

                                            {boolean}

                                          property isInSubnet

                                          isInSubnet: (this: Address4 | Address6, address: Address4 | Address6) => boolean;
                                          • Returns true if the given address is in the subnet of the current address Address6

                                            Returns

                                            {boolean}

                                          property parsedAddress

                                          parsedAddress: string[];

                                            property parsedAddress4

                                            parsedAddress4?: string;

                                              property parsedSubnet

                                              parsedSubnet: string;

                                                property subnet

                                                subnet: string;

                                                  property subnetMask

                                                  subnetMask: number;

                                                    property v4

                                                    v4: boolean;

                                                      property zone

                                                      zone: string;

                                                        method bigInteger

                                                        bigInteger: () => any;
                                                        • Return the address as a BigInteger Address6

                                                          Returns

                                                          {BigInteger}

                                                        method binaryZeroPad

                                                        binaryZeroPad: () => string;
                                                        • Return a zero-padded base-2 string representation of the address Address6

                                                          Returns

                                                          {String}

                                                          Example 1

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

                                                        method canonicalForm

                                                        canonicalForm: () => string;
                                                        • Return the canonical form of the address Address6

                                                          Returns

                                                          {String}

                                                        method correctForm

                                                        correctForm: () => string;
                                                        • Return the correct form of the address Address6

                                                          Returns

                                                          {String}

                                                        method decimal

                                                        decimal: () => string;
                                                        • Return the decimal form of the address Address6

                                                          Returns

                                                          {String}

                                                        method endAddress

                                                        endAddress: () => Address6;
                                                        • The last address in the range given by this address' subnet Often referred to as the Broadcast Address6

                                                          Returns

                                                          {Address6}

                                                        method endAddressExclusive

                                                        endAddressExclusive: () => Address6;
                                                        • The last host address in the range given by this address's subnet ie the last address prior to the Broadcast Address Address6

                                                          Returns

                                                          {Address6}

                                                        method fromAddress4

                                                        static fromAddress4: (address: string) => Address6;
                                                        • Create an IPv6-mapped address given an IPv4 address Address6

                                                          Parameter address

                                                          An IPv4 address string

                                                          Returns

                                                          {Address6}

                                                          Example 1

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

                                                        method fromArpa

                                                        static fromArpa: (arpaFormAddress: string) => Address6;
                                                        • Return an address from ip6.arpa form Address6

                                                          Parameter arpaFormAddress

                                                          an 'ip6.arpa' form address

                                                          Returns

                                                          {Adress6}

                                                          Example 1

                                                          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'

                                                        method fromBigInteger

                                                        static fromBigInteger: (bigInteger: any) => Address6;
                                                        • Convert a BigInteger to a v6 address object Address6

                                                          Parameter bigInteger

                                                          a BigInteger to convert

                                                          Returns

                                                          {Address6}

                                                          Example 1

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

                                                        method fromByteArray

                                                        static fromByteArray: (bytes: Array<any>) => Address6;
                                                        • Convert a byte array to an Address6 object Address6

                                                          Returns

                                                          {Address6}

                                                        method fromUnsignedByteArray

                                                        static fromUnsignedByteArray: (bytes: Array<any>) => Address6;
                                                        • Convert an unsigned byte array to an Address6 object Address6

                                                          Returns

                                                          {Address6}

                                                        method fromURL

                                                        static fromURL: (
                                                        url: string
                                                        ) =>
                                                        | { error: string; address: null; port: null }
                                                        | { address: Address6; port: number | null; error?: undefined };
                                                        • Convert a URL (with optional port number) to an address object Address6

                                                          Parameter url

                                                          a URL with optional port number

                                                          Example 1

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

                                                        method getBits

                                                        getBits: (start: number, end: number) => any;
                                                        • Return the bits in the given range as a BigInteger Address6

                                                          Returns

                                                          {BigInteger}

                                                        method getBitsBase16

                                                        getBitsBase16: (start: number, end: number) => string;
                                                        • Return the bits in the given range as a base-16 string Address6

                                                          Returns

                                                          {String}

                                                        method getBitsBase2

                                                        getBitsBase2: (start: number, end: number) => string;
                                                        • Return the bits in the given range as a base-2 string Address6

                                                          Returns

                                                          {String}

                                                        method getBitsPastSubnet

                                                        getBitsPastSubnet: () => string;
                                                        • Return the bits that are set past the subnet mask length Address6

                                                          Returns

                                                          {String}

                                                        method getScope

                                                        getScope: () => string;
                                                        • Return the scope of the address Address6

                                                          Returns

                                                          {String}

                                                        method getType

                                                        getType: () => string;
                                                        • Return the type of the address Address6

                                                          Returns

                                                          {String}

                                                        method group

                                                        group: () => string;
                                                        • Groups an address

                                                          Returns

                                                          {String}

                                                        method href

                                                        href: (optionalPort?: number | string) => string;
                                                        • Returns

                                                          {String} the address in link form with a default port of 80

                                                        method inspect6to4

                                                        inspect6to4: () => SixToFourProperties;
                                                        • Return an object containing the 6to4 properties of the address Address6

                                                          Returns

                                                          {Object}

                                                        method inspectTeredo

                                                        inspectTeredo: () => TeredoProperties;
                                                        • Return an object containing the Teredo properties of the address Address6

                                                          Returns

                                                          {Object}

                                                        method is4

                                                        is4: () => boolean;
                                                        • Returns true if the address is a v4-in-v6 address, false otherwise Address6

                                                          Returns

                                                          {boolean}

                                                        method is6to4

                                                        is6to4: () => boolean;
                                                        • Returns true if the address is a 6to4 address, false otherwise Address6

                                                          Returns

                                                          {boolean}

                                                        method isCanonical

                                                        isCanonical: () => boolean;
                                                        • Returns true if the address is in the canonical form, false otherwise Address6

                                                          Returns

                                                          {boolean}

                                                        method isLinkLocal

                                                        isLinkLocal: () => boolean;
                                                        • Returns true if the address is a link local address, false otherwise Address6

                                                          Returns

                                                          {boolean}

                                                        method isLoopback

                                                        isLoopback: () => boolean;
                                                        • Returns true if the address is a loopback address, false otherwise Address6

                                                          Returns

                                                          {boolean}

                                                        method isMulticast

                                                        isMulticast: () => boolean;
                                                        • Returns true if the address is a multicast address, false otherwise Address6

                                                          Returns

                                                          {boolean}

                                                        method isTeredo

                                                        isTeredo: () => boolean;
                                                        • Returns true if the address is a Teredo address, false otherwise Address6

                                                          Returns

                                                          {boolean}

                                                        method isValid

                                                        static isValid: (address: string) => boolean;
                                                          link: (options?: {
                                                          className?: string;
                                                          prefix?: string;
                                                          v4?: boolean;
                                                          }) => string;
                                                          • Returns

                                                            {String} a link suitable for conveying the address via a URL hash

                                                          method mask

                                                          mask: (mask?: number) => string;
                                                          • Return the first n bits of the address, defaulting to the subnet mask Address6

                                                            Parameter mask

                                                            the number of bits to mask

                                                            Returns

                                                            {String} the first n bits of the address as a string

                                                          method microsoftTranscription

                                                          microsoftTranscription: () => string;
                                                          • Return the Microsoft UNC transcription of the address Address6

                                                            Returns

                                                            {String} the Microsoft UNC transcription of the address

                                                          method parse

                                                          parse: (address: string) => string[];

                                                            method parse4in6

                                                            parse4in6: (address: string) => string;

                                                              method possibleSubnets

                                                              possibleSubnets: (subnetSize?: number) => string;
                                                              • Return the number of possible subnets of a given size in the address Address6

                                                                Parameter size

                                                                the subnet size

                                                                Returns

                                                                {String}

                                                              method regularExpression

                                                              regularExpression: (this: Address6, substringSearch?: boolean) => RegExp;
                                                              • Generate a regular expression that can be used to find or validate all variations of this address. Address6

                                                                Parameter substringSearch

                                                                Returns

                                                                {RegExp}

                                                              method regularExpressionString

                                                              regularExpressionString: (this: Address6, substringSearch?: boolean) => string;
                                                              • Generate a regular expression string that can be used to find or validate all variations of this address Address6

                                                                Parameter substringSearch

                                                                Returns

                                                                {string}

                                                              method reverseForm

                                                              reverseForm: (options?: common.ReverseFormOptions) => string;
                                                              • Return the reversed ip6.arpa form of the address Address6

                                                                Parameter options

                                                                Parameter

                                                                {boolean} options.omitSuffix - omit the "ip6.arpa" suffix

                                                                Returns

                                                                {String}

                                                              method startAddress

                                                              startAddress: () => Address6;
                                                              • The first address in the range given by this address' subnet Often referred to as the Network Address. Address6

                                                                Returns

                                                                {Address6}

                                                              method startAddressExclusive

                                                              startAddressExclusive: () => Address6;
                                                              • The first host address in the range given by this address's subnet ie the first address after the Network Address Address6

                                                                Returns

                                                                {Address6}

                                                              method to4

                                                              to4: () => Address4;
                                                              • Return the last two groups of this address as an IPv4 address string Address6

                                                                Returns

                                                                {Address4}

                                                                Example 1

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

                                                              method to4in6

                                                              to4in6: () => string;
                                                              • Return the v4-in-v6 form of the address Address6

                                                                Returns

                                                                {String}

                                                              method to6to4

                                                              to6to4: () => Address6 | null;
                                                              • Return a v6 6to4 address from a v6 v4inv6 address Address6

                                                                Returns

                                                                {Address6}

                                                              method toByteArray

                                                              toByteArray: () => number[];
                                                              • Return a byte array Address6

                                                                Returns

                                                                {Array}

                                                              method toUnsignedByteArray

                                                              toUnsignedByteArray: () => number[];
                                                              • Return an unsigned byte array Address6

                                                                Returns

                                                                {Array}

                                                              class AddressError

                                                              class AddressError extends Error {}

                                                                constructor

                                                                constructor(message: string, parseMessage?: string);

                                                                  property parseMessage

                                                                  parseMessage?: string;

                                                                    Package Files (4)

                                                                    Dependencies (2)

                                                                    Dev Dependencies (27)

                                                                    Peer Dependencies (0)

                                                                    No peer dependencies.

                                                                    Badge

                                                                    To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                                                                    You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/ip-address.

                                                                    • Markdown
                                                                      [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/ip-address)
                                                                    • HTML
                                                                      <a href="https://www.jsdocs.io/package/ip-address"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>