A library for parsing IPv4 and IPv6 IP addresses in node and the browser.
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Identification and analysis of special address types including multicast, loopback, Teredo, 6to4, and other reserved address ranges for both IPv4 and IPv6.
IPv4 addresses have fewer special types compared to IPv6, but multicast detection is essential for networking applications.
/**
* Check if IPv4 address is a multicast address (224.0.0.0/4 range)
* Available on Address4 instances
* @returns true if the address is in the multicast range
*/
isMulticast(): boolean;IPv4 Examples:
import { Address4 } from "ip-address";
// Multicast addresses (224.0.0.0 to 239.255.255.255)
const multicast1 = new Address4("224.0.0.1");
const multicast2 = new Address4("239.255.255.255");
const unicast = new Address4("192.168.1.1");
console.log(multicast1.isMulticast()); // true
console.log(multicast2.isMulticast()); // true
console.log(unicast.isMulticast()); // false
// Well-known multicast addresses
const allHosts = new Address4("224.0.0.1");
const allRouters = new Address4("224.0.0.2");
const ospf = new Address4("224.0.0.5");
console.log(`All Hosts: ${allHosts.isMulticast()}`); // true
console.log(`All Routers: ${allRouters.isMulticast()}`); // true
console.log(`OSPF: ${ospf.isMulticast()}`); // trueIPv6 has a rich type system with various special-use addresses and scopes.
/**
* Get the scope of the IPv6 address
* Available on Address6 instances
* @returns Scope string (e.g., "Global", "Link local", "Site local", "Interface local")
*/
getScope(): string;
/**
* Get the type/category of the IPv6 address
* Available on Address6 instances
* @returns Type string describing the address category
*/
getType(): string;
/**
* Check if address is a multicast address (ff00::/8)
* Available on Address6 instances
* @returns true if multicast address
*/
isMulticast(): boolean;
/**
* Check if address is the loopback address (::1)
* Available on Address6 instances
* @returns true if loopback address
*/
isLoopback(): boolean;
/**
* Check if address is link-local (fe80::/10 with specific zero pattern)
* Available on Address6 instances
* @returns true if properly formatted link-local address
*/
isLinkLocal(): boolean;
/**
* Check if address contains an IPv4 component (IPv4-in-IPv6)
* Available on Address6 instances
* @returns true if address has embedded IPv4
*/
is4(): boolean;
/**
* Check if address is in canonical form (IPv6 only)
* Available on Address6 instances
* @returns true if address is in canonical representation
*/
isCanonical(): boolean;IPv6 Basic Type Examples:
import { Address6 } from "ip-address";
// Global unicast
const global = new Address6("2001:db8::1");
console.log(global.getType()); // "Global unicast"
console.log(global.getScope()); // "Global"
// Loopback
const loopback = new Address6("::1");
console.log(loopback.getType()); // "Loopback"
console.log(loopback.isLoopback()); // true
// Link-local
const linkLocal = new Address6("fe80::1");
console.log(linkLocal.getType()); // "Link-local unicast"
console.log(linkLocal.getScope()); // "Link local"
console.log(linkLocal.isLinkLocal()); // true
// Multicast
const multicast = new Address6("ff02::1");
console.log(multicast.getType()); // "Multicast (All nodes on this link)"
console.log(multicast.getScope()); // "Link local"
console.log(multicast.isMulticast()); // trueIPv6 Multicast Examples:
// Various multicast scopes and purposes
const examples = [
{ addr: "ff01::1", desc: "Interface-local all nodes" },
{ addr: "ff02::1", desc: "Link-local all nodes" },
{ addr: "ff02::2", desc: "Link-local all routers" },
{ addr: "ff05::2", desc: "Site-local all routers" },
{ addr: "ff02::5", desc: "OSPFv3 AllSPF routers" },
{ addr: "ff02::fb", desc: "mDNSv6" },
{ addr: "ff02::1:2", desc: "All DHCP servers and relay agents" }
];
examples.forEach(({ addr, desc }) => {
const address = new Address6(addr);
console.log(`${addr}: ${address.getType()}`);
console.log(` Scope: ${address.getScope()}`);
console.log(` Multicast: ${address.isMulticast()}`);
console.log(` Description: ${desc}\n`);
});IPv6 addresses used for IPv4-to-IPv6 transition mechanisms.
/**
* Check if address is a Teredo address (2001::/32)
* Available on Address6 instances
* @returns true if Teredo tunneling address
*/
isTeredo(): boolean;
/**
* Check if address is a 6to4 address (2002::/16)
* Available on Address6 instances
* @returns true if 6to4 transition address
*/
is6to4(): boolean;Teredo Examples:
// Teredo addresses (2001::/32 prefix)
const teredo1 = new Address6("2001:0:ce49:7601:e866:efff:62c3:fffe");
const teredo2 = new Address6("2001:0:1234:5678:abcd:ef01:2345:6789");
const regular = new Address6("2002:c000:0204::"); // 6to4, not Teredo
console.log(teredo1.isTeredo()); // true
console.log(teredo2.isTeredo()); // true
console.log(regular.isTeredo()); // false
console.log(teredo1.getType()); // "Global unicast"
console.log(teredo1.getScope()); // "Global"6to4 Examples:
// 6to4 addresses (2002::/16 prefix)
const sixToFour1 = new Address6("2002:c000:0204::"); // 192.0.2.4 embedded
const sixToFour2 = new Address6("2002:cb00:7100::"); // 203.0.113.0 embedded
const regular = new Address6("2001:db8::1");
console.log(sixToFour1.is6to4()); // true
console.log(sixToFour2.is6to4()); // true
console.log(regular.is6to4()); // false
console.log(sixToFour1.getType()); // "Global unicast"
console.log(sixToFour1.getScope()); // "Global"Detect and analyze addresses that contain embedded IPv4 components.
IPv4-in-IPv6 Examples:
// IPv4-mapped IPv6 addresses (::ffff:x.x.x.x)
const mapped = new Address6("::ffff:192.168.1.1");
console.log(mapped.is4()); // true
console.log(mapped.getType()); // "Global unicast"
// IPv4-compatible IPv6 addresses (::x.x.x.x) - deprecated
const compatible = new Address6("::192.168.1.1");
console.log(compatible.is4()); // true
// 6to4 with IPv4 embedding
const sixToFour = new Address6("2002:c0a8:0101::"); // ::ffff:192.168.1.1 embedded
console.log(sixToFour.is4()); // false (no direct IPv4 component)
console.log(sixToFour.is6to4()); // true
// Extract IPv4 from mapped addresses
if (mapped.is4() && mapped.address4) {
console.log(`Embedded IPv4: ${mapped.address4.correctForm()}`); // "192.168.1.1"
}Combine multiple type checks for complete address analysis.
Complete Analysis Function:
function analyzeAddress(addrStr: string) {
try {
// Try IPv6 first
const addr6 = new Address6(addrStr);
console.log(`IPv6 Address: ${addr6.correctForm()}`);
console.log(`Type: ${addr6.getType()}`);
console.log(`Scope: ${addr6.getScope()}`);
console.log(`Canonical: ${addr6.canonicalForm()}`);
const properties = [];
if (addr6.isMulticast()) properties.push("Multicast");
if (addr6.isLoopback()) properties.push("Loopback");
if (addr6.isLinkLocal()) properties.push("Link-local");
if (addr6.isTeredo()) properties.push("Teredo");
if (addr6.is6to4()) properties.push("6to4");
if (addr6.is4()) properties.push("Contains IPv4");
if (properties.length > 0) {
console.log(`Special properties: ${properties.join(", ")}`);
}
if (addr6.is4() && addr6.address4) {
console.log(`Embedded IPv4: ${addr6.address4.correctForm()}`);
}
} catch (e) {
// Try IPv4
try {
const addr4 = new Address4(addrStr);
console.log(`IPv4 Address: ${addr4.correctForm()}`);
console.log(`Subnet: ${addr4.subnet}`);
const properties = [];
if (addr4.isMulticast()) properties.push("Multicast");
if (properties.length > 0) {
console.log(`Special properties: ${properties.join(", ")}`);
}
} catch (e2) {
console.log(`Invalid address: ${addrStr}`);
}
}
}
// Test various address types
const testAddresses = [
"192.168.1.1", // IPv4 unicast
"224.0.0.1", // IPv4 multicast
"::1", // IPv6 loopback
"fe80::1", // IPv6 link-local
"ff02::1", // IPv6 multicast
"2001:db8::1", // IPv6 global unicast
"::ffff:192.168.1.1", // IPv4-mapped IPv6
"2001:0:ce49:7601::1", // Teredo
"2002:c000:0204::", // 6to4
];
testAddresses.forEach(addr => {
console.log(`\n=== Analysis of ${addr} ===`);
analyzeAddress(addr);
});The library includes predefined constants for various IPv6 address types and scopes.
IPv6 Scopes:
0: Reserved1: Interface local2: Link local4: Admin local5: Site local8: Organization local14: Global15: ReservedIPv6 Well-known Types:
::1/128: Loopback::/128: Unspecifiedff00::/8: Multicastfe80::/10: Link-local unicastThese constants are used internally by the getType() and getScope() methods to provide descriptive strings for address classification.