What is ip6addr?
The ip6addr npm package provides utilities for handling and manipulating IPv6 addresses. It allows for parsing, comparing, and performing various operations on IPv6 addresses.
What are ip6addr's main functionalities?
Parsing IPv6 Addresses
This feature allows you to parse a given IPv6 address string into an address object that can be manipulated or queried.
const ip6addr = require('ip6addr');
const addr = ip6addr.parse('2001:0db8::ff00:0042:8329');
console.log(addr.toString());
Comparing IPv6 Addresses
This feature allows you to compare two IPv6 addresses. The comparison can determine if one address is greater than, less than, or equal to another.
const ip6addr = require('ip6addr');
const addr1 = ip6addr.parse('2001:0db8::ff00:0042:8329');
const addr2 = ip6addr.parse('2001:0db8::ff00:0042:832a');
console.log(ip6addr.compare(addr1, addr2));
Checking if an Address is in a Subnet
This feature allows you to check if a given IPv6 address is within a specified subnet.
const ip6addr = require('ip6addr');
const addr = ip6addr.parse('2001:0db8::ff00:0042:8329');
const subnet = ip6addr.createCIDR('2001:0db8::/32');
console.log(subnet.contains(addr));
Converting IPv6 to IPv4-mapped Address
This feature allows you to convert an IPv6 address to its IPv4-mapped address if applicable.
const ip6addr = require('ip6addr');
const addr = ip6addr.parse('::ffff:192.168.1.1');
console.log(addr.toIPv4Address().toString());
Other packages similar to ip6addr
ip-address
The ip-address package provides similar functionalities for both IPv4 and IPv6 addresses. It allows for parsing, validating, and manipulating IP addresses. Compared to ip6addr, it offers a more comprehensive set of tools for both IPv4 and IPv6.
ip6
The ip6 package focuses on IPv6 address manipulation and validation. It provides utilities for parsing, formatting, and comparing IPv6 addresses. While it offers similar functionalities to ip6addr, it is more specialized in IPv6.
ip
The ip package provides utilities for both IPv4 and IPv6 address manipulation. It includes functions for parsing, validating, and converting IP addresses. It is a more general-purpose package compared to ip6addr, which is specialized in IPv6.
ip6addr is a small library for manipulating IP addresses in Javascript.
Inspired by ipaddr.js, ip6addr
focuses on better IPv6 support, particularly in cases where IPv4 and IPv6
addresses are used together.
Installation
npm install ip6addr
API
The ip6addr API is designed around three object types: Addr
, CIDR
and
AddrRange
. These are designed to be immutable once created. The module
provides public functions for instantiating these objects:
- parse: Parse an IPv4 or IPv6 address
- createCIDR: Create a CIDR object
- createAddrRange: Create an AddrRange object
License
This Source Code Form is subject to the terms of the Mozilla Public License, v.
2.0. For the full license text see LICENSE, or http://mozilla.org/MPL/2.0/.
Copyright (c) 2015, Joyent, Inc.