cidr-block - v2.1.1
    Preparing search index...

    Function address

    • Creates a new Ipv4Address instance from the given literal. Valid formats include string, number, or octet array.

      Parameters

      Returns Ipv4Address

      A new Ipv4Address instance.

      import { ipv4 } from 'cidr-block';

      const addr1 = ipv4.address("192.168.1.1");
      const addr2 = ipv4.address(3232235777);
      const addr3 = ipv4.address([192, 168, 1, 1]);
      import { ipv4 } from 'cidr-block';

      const addr = ipv4.address("192.168.1.1");
      addr.toString(); // "192.168.1.1"
      addr.toNumber(); // 3232235777
      addr.octets(); // [192, 168, 1, 1]
      addr.toBinaryString(); // "11000000.10101000.00000001.00000001"
      import { ipv4 } from 'cidr-block';

      const addr = ipv4.address("192.168.1.1");
      addr.equals("192.168.1.1"); // true
      addr.isGreaterThan("192.168.1.0"); // true
      addr.isLessThan("192.168.1.2"); // true
      import { ipv4 } from 'cidr-block';

      const addr = ipv4.address("192.168.1.1");
      addr.nextAddress()?.toString(); // "192.168.1.2"
      addr.previousAddress()?.toString(); // "192.168.1.0"
      import { ipv4 } from 'cidr-block';

      ipv4.address("127.0.0.1").isLoopbackAddress(); // true
      ipv4.address("10.0.0.1").isPrivateAddress(); // true
      ipv4.address("169.254.1.1").isLocalLinkAddress(); // true
      ipv4.address("224.0.0.1").isMulticastAddress(); // true

      If the input is not a valid IPv4 address.