Skip to content

Commit f01d742

Browse files
Add address-property predicates (private, ULA, loopback, link-local, etc.) (#197)
Adds isPrivate / isLoopback / isLinkLocal / isUnspecified / isBroadcast / isCGNAT to Address4, and isULA / isUnspecified / isDocumentation to Address6. Closes #53 (which asked for isPrivate and ULA detection). The README previously advertised ULA support but no isULA() existed — this fixes the discrepancy.
1 parent f19e31b commit f01d742

6 files changed

Lines changed: 268 additions & 9 deletions

File tree

‎README.md‎

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ link.isLinkLocal(); // true
4646
link.isMulticast(); // false
4747
link.isLoopback(); // false
4848

49+
new Address4('192.168.1.1').isPrivate(); // true (RFC 1918)
50+
new Address6('fc00::1').isULA(); // true (RFC 4193)
51+
4952
// Numeric and byte representations
5053
v4.bigInt(); // 3232235777n
5154
v4.toArray(); // [192, 168, 1, 1]
@@ -66,7 +69,7 @@ Address6.fromURL('http://[2001:db8::1]:8080/').port; // 8080
6669
- Parses all standard IPv4 and IPv6 notations, including subnets and zones
6770
- Parses IPv6 hosts (and ports) from URLs via `Address6.fromURL(url)`
6871
- Subnet membership checks (`isInSubnet`) and range queries (`startAddress` / `endAddress`)
69-
- Special-property checks: multicast, loopback, link-local, ULA, Teredo, 6to4, v4-in-v6
72+
- Special-property checks: private (RFC 1918) / ULA (RFC 4193), loopback, link-local, multicast, broadcast, unspecified, CGNAT, documentation, Teredo, 6to4, v4-in-v6
7073
- Decodes [Teredo](http://en.wikipedia.org/wiki/Teredo_tunneling#IPv6_addressing) and 6to4 tunneling information
7174
- Conversions: canonical/correct form, hex, binary, decimal, byte arrays, BigInt, `in-addr.arpa` / `ip6.arpa`
7275
- Runs in Node.js and the browser
@@ -137,8 +140,14 @@ Represents an IPv4 address
137140
- `getBitsBase2(start: number, end: number): string` — Returns the bits in the given range as a base-2 string [src](https://github.com/beaugunderson/ip-address/blob/master/src/ipv4.ts#L394)
138141
- `reverseForm(options?: ReverseFormOptions): string` — Return the reversed ip6.arpa form of the address [src](https://github.com/beaugunderson/ip-address/blob/master/src/ipv4.ts#L404)
139142
- `isMulticast(): boolean` — Returns true if the given address is a multicast address [src](https://github.com/beaugunderson/ip-address/blob/master/src/ipv4.ts#L428)
140-
- `binaryZeroPad(): string` — Returns a zero-padded base-2 string representation of the address [src](https://github.com/beaugunderson/ip-address/blob/master/src/ipv4.ts#L436)
141-
- `groupForV6(): string` — Groups an IPv4 address for inclusion at the end of an IPv6 address [src](https://github.com/beaugunderson/ip-address/blob/master/src/ipv4.ts#L447)
143+
- `isPrivate(): boolean` — Returns true if the address is in one of the [RFC 1918](https://datatracker.ietf.org/doc/html/rfc1918) private address ranges (`10.0.0.0/8`, `172.16.0.0/12`, `192.168.0.0/16`). [src](https://github.com/beaugunderson/ip-address/blob/master/src/ipv4.ts#L436)
144+
- `isLoopback(): boolean` — Returns true if the address is in the loopback range `127.0.0.0/8` ([RFC 1122](https://datatracker.ietf.org/doc/html/rfc1122)). [src](https://github.com/beaugunderson/ip-address/blob/master/src/ipv4.ts#L444)
145+
- `isLinkLocal(): boolean` — Returns true if the address is in the link-local range `169.254.0.0/16` ([RFC 3927](https://datatracker.ietf.org/doc/html/rfc3927)). [src](https://github.com/beaugunderson/ip-address/blob/master/src/ipv4.ts#L452)
146+
- `isUnspecified(): boolean` — Returns true if the address is the unspecified address `0.0.0.0`. [src](https://github.com/beaugunderson/ip-address/blob/master/src/ipv4.ts#L460)
147+
- `isBroadcast(): boolean` — Returns true if the address is the limited broadcast address `255.255.255.255` ([RFC 919](https://datatracker.ietf.org/doc/html/rfc919)). [src](https://github.com/beaugunderson/ip-address/blob/master/src/ipv4.ts#L468)
148+
- `isCGNAT(): boolean` — Returns true if the address is in the carrier-grade NAT range `100.64.0.0/10` ([RFC 6598](https://datatracker.ietf.org/doc/html/rfc6598)). [src](https://github.com/beaugunderson/ip-address/blob/master/src/ipv4.ts#L476)
149+
- `binaryZeroPad(): string` — Returns a zero-padded base-2 string representation of the address [src](https://github.com/beaugunderson/ip-address/blob/master/src/ipv4.ts#L484)
150+
- `groupForV6(): string` — Groups an IPv4 address for inclusion at the end of an IPv6 address [src](https://github.com/beaugunderson/ip-address/blob/master/src/ipv4.ts#L495)
142151

143152
**Properties**
144153

@@ -215,11 +224,14 @@ Represents an IPv6 address
215224
- `isTeredo(): boolean` — Returns true if the address is a Teredo address, false otherwise [src](https://github.com/beaugunderson/ip-address/blob/master/src/ipv6.ts#L1186)
216225
- `is6to4(): boolean` — Returns true if the address is a 6to4 address, false otherwise [src](https://github.com/beaugunderson/ip-address/blob/master/src/ipv6.ts#L1194)
217226
- `isLoopback(): boolean` — Returns true if the address is a loopback address, false otherwise [src](https://github.com/beaugunderson/ip-address/blob/master/src/ipv6.ts#L1202)
218-
- `href(optionalPort?: string | number): string` — Returns the address as an HTTP URL with the host bracketed, e.g. `http://[2001:db8::1]/`. If `optionalPort` is provided it is appended, e.g. `http://[2001:db8::1]:8080/`. [src](https://github.com/beaugunderson/ip-address/blob/master/src/ipv6.ts#L1213)
219-
- `link(options?: { className?: string; prefix?: string; v4?: boolean }): string` — Returns an HTML `<a>` element whose `href` encodes the address in a URL hash fragment (default prefix `/#address=`). Useful for linking between pages of an address-inspector UI. [src](https://github.com/beaugunderson/ip-address/blob/master/src/ipv6.ts#L1231)
220-
- `group(): string` — Groups an address [src](https://github.com/beaugunderson/ip-address/blob/master/src/ipv6.ts#L1271)
221-
- `regularExpressionString(this: Address6, substringSearch: boolean): string` — Generate a regular expression string that can be used to find or validate all variations of this address [src](https://github.com/beaugunderson/ip-address/blob/master/src/ipv6.ts#L1323)
222-
- `regularExpression(this: Address6, substringSearch: boolean): RegExp` — Generate a regular expression that can be used to find or validate all variations of this address. [src](https://github.com/beaugunderson/ip-address/blob/master/src/ipv6.ts#L1377)
227+
- `isULA(): boolean` — Returns true if the address is a Unique Local Address in `fc00::/7` ([RFC 4193](https://datatracker.ietf.org/doc/html/rfc4193)). ULAs are the IPv6 equivalent of IPv4 [RFC 1918](https://datatracker.ietf.org/doc/html/rfc1918) private addresses. [src](https://github.com/beaugunderson/ip-address/blob/master/src/ipv6.ts#L1210)
228+
- `isUnspecified(): boolean` — Returns true if the address is the unspecified address `::`. [src](https://github.com/beaugunderson/ip-address/blob/master/src/ipv6.ts#L1218)
229+
- `isDocumentation(): boolean` — Returns true if the address is in the documentation prefix `2001:db8::/32` ([RFC 3849](https://datatracker.ietf.org/doc/html/rfc3849)). [src](https://github.com/beaugunderson/ip-address/blob/master/src/ipv6.ts#L1226)
230+
- `href(optionalPort?: string | number): string` — Returns the address as an HTTP URL with the host bracketed, e.g. `http://[2001:db8::1]/`. If `optionalPort` is provided it is appended, e.g. `http://[2001:db8::1]:8080/`. [src](https://github.com/beaugunderson/ip-address/blob/master/src/ipv6.ts#L1237)
231+
- `link(options?: { className?: string; prefix?: string; v4?: boolean }): string` — Returns an HTML `<a>` element whose `href` encodes the address in a URL hash fragment (default prefix `/#address=`). Useful for linking between pages of an address-inspector UI. [src](https://github.com/beaugunderson/ip-address/blob/master/src/ipv6.ts#L1255)
232+
- `group(): string` — Groups an address [src](https://github.com/beaugunderson/ip-address/blob/master/src/ipv6.ts#L1295)
233+
- `regularExpressionString(this: Address6, substringSearch: boolean): string` — Generate a regular expression string that can be used to find or validate all variations of this address [src](https://github.com/beaugunderson/ip-address/blob/master/src/ipv6.ts#L1347)
234+
- `regularExpression(this: Address6, substringSearch: boolean): RegExp` — Generate a regular expression that can be used to find or validate all variations of this address. [src](https://github.com/beaugunderson/ip-address/blob/master/src/ipv6.ts#L1401)
223235

224236
**Properties**
225237

‎scripts/readme-template.md‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ link.isLinkLocal(); // true
4646
link.isMulticast(); // false
4747
link.isLoopback(); // false
4848

49+
new Address4('192.168.1.1').isPrivate(); // true (RFC 1918)
50+
new Address6('fc00::1').isULA(); // true (RFC 4193)
51+
4952
// Numeric and byte representations
5053
v4.bigInt(); // 3232235777n
5154
v4.toArray(); // [192, 168, 1, 1]
@@ -66,7 +69,7 @@ Address6.fromURL('http://[2001:db8::1]:8080/').port; // 8080
6669
- Parses all standard IPv4 and IPv6 notations, including subnets and zones
6770
- Parses IPv6 hosts (and ports) from URLs via `Address6.fromURL(url)`
6871
- Subnet membership checks (`isInSubnet`) and range queries (`startAddress` / `endAddress`)
69-
- Special-property checks: multicast, loopback, link-local, ULA, Teredo, 6to4, v4-in-v6
72+
- Special-property checks: private (RFC 1918) / ULA (RFC 4193), loopback, link-local, multicast, broadcast, unspecified, CGNAT, documentation, Teredo, 6to4, v4-in-v6
7073
- Decodes [Teredo](http://en.wikipedia.org/wiki/Teredo_tunneling#IPv6_addressing) and 6to4 tunneling information
7174
- Conversions: canonical/correct form, hex, binary, decimal, byte arrays, BigInt, `in-addr.arpa` / `ip6.arpa`
7275
- Runs in Node.js and the browser

‎src/ipv4.ts‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,54 @@ export class Address4 {
429429
return this.isInSubnet(MULTICAST_V4);
430430
}
431431

432+
/**
433+
* Returns true if the address is in one of the [RFC 1918](https://datatracker.ietf.org/doc/html/rfc1918) private address ranges (`10.0.0.0/8`, `172.16.0.0/12`, `192.168.0.0/16`).
434+
* @returns {boolean}
435+
*/
436+
isPrivate(): boolean {
437+
return PRIVATE_V4.some((subnet) => this.isInSubnet(subnet));
438+
}
439+
440+
/**
441+
* Returns true if the address is in the loopback range `127.0.0.0/8` ([RFC 1122](https://datatracker.ietf.org/doc/html/rfc1122)).
442+
* @returns {boolean}
443+
*/
444+
isLoopback(): boolean {
445+
return this.isInSubnet(LOOPBACK_V4);
446+
}
447+
448+
/**
449+
* Returns true if the address is in the link-local range `169.254.0.0/16` ([RFC 3927](https://datatracker.ietf.org/doc/html/rfc3927)).
450+
* @returns {boolean}
451+
*/
452+
isLinkLocal(): boolean {
453+
return this.isInSubnet(LINK_LOCAL_V4);
454+
}
455+
456+
/**
457+
* Returns true if the address is the unspecified address `0.0.0.0`.
458+
* @returns {boolean}
459+
*/
460+
isUnspecified(): boolean {
461+
return this.isInSubnet(UNSPECIFIED_V4);
462+
}
463+
464+
/**
465+
* Returns true if the address is the limited broadcast address `255.255.255.255` ([RFC 919](https://datatracker.ietf.org/doc/html/rfc919)).
466+
* @returns {boolean}
467+
*/
468+
isBroadcast(): boolean {
469+
return this.isInSubnet(BROADCAST_V4);
470+
}
471+
472+
/**
473+
* Returns true if the address is in the carrier-grade NAT range `100.64.0.0/10` ([RFC 6598](https://datatracker.ietf.org/doc/html/rfc6598)).
474+
* @returns {boolean}
475+
*/
476+
isCGNAT(): boolean {
477+
return this.isInSubnet(CGNAT_V4);
478+
}
479+
432480
/**
433481
* Returns a zero-padded base-2 string representation of the address
434482
* @returns {string}
@@ -459,3 +507,13 @@ export class Address4 {
459507
}
460508

461509
const MULTICAST_V4 = new Address4('224.0.0.0/4');
510+
const PRIVATE_V4 = [
511+
new Address4('10.0.0.0/8'),
512+
new Address4('172.16.0.0/12'),
513+
new Address4('192.168.0.0/16'),
514+
];
515+
const LOOPBACK_V4 = new Address4('127.0.0.0/8');
516+
const LINK_LOCAL_V4 = new Address4('169.254.0.0/16');
517+
const UNSPECIFIED_V4 = new Address4('0.0.0.0/32');
518+
const BROADCAST_V4 = new Address4('255.255.255.255/32');
519+
const CGNAT_V4 = new Address4('100.64.0.0/10');

‎src/ipv6.ts‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,6 +1202,30 @@ export class Address6 {
12021202
isLoopback(): boolean {
12031203
return this.getType() === 'Loopback';
12041204
}
1205+
1206+
/**
1207+
* Returns true if the address is a Unique Local Address in `fc00::/7` ([RFC 4193](https://datatracker.ietf.org/doc/html/rfc4193)). ULAs are the IPv6 equivalent of IPv4 [RFC 1918](https://datatracker.ietf.org/doc/html/rfc1918) private addresses.
1208+
* @returns {boolean}
1209+
*/
1210+
isULA(): boolean {
1211+
return this.isInSubnet(ULA_SUBNET);
1212+
}
1213+
1214+
/**
1215+
* Returns true if the address is the unspecified address `::`.
1216+
* @returns {boolean}
1217+
*/
1218+
isUnspecified(): boolean {
1219+
return this.getType() === 'Unspecified';
1220+
}
1221+
1222+
/**
1223+
* Returns true if the address is in the documentation prefix `2001:db8::/32` ([RFC 3849](https://datatracker.ietf.org/doc/html/rfc3849)).
1224+
* @returns {boolean}
1225+
*/
1226+
isDocumentation(): boolean {
1227+
return this.isInSubnet(DOCUMENTATION_SUBNET);
1228+
}
12051229
// #endregion
12061230

12071231
// #region HTML
@@ -1386,3 +1410,5 @@ const TYPE_SUBNETS: Array<[Address6, string]> = Object.keys(constants6.TYPES).ma
13861410
]);
13871411
const TEREDO_SUBNET = new Address6('2001::/32');
13881412
const SIX_TO_FOUR_SUBNET = new Address6('2002::/16');
1413+
const ULA_SUBNET = new Address6('fc00::/7');
1414+
const DOCUMENTATION_SUBNET = new Address6('2001:db8::/32');

‎test/functionality-v4-test.ts‎

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,4 +486,101 @@ describe('v4', () => {
486486
});
487487
});
488488
});
489+
490+
describe('isPrivate', () => {
491+
it('detects RFC 1918 ranges', () => {
492+
notationsToAddresseses([
493+
'10.0.0.0',
494+
'10.255.255.255',
495+
'172.16.0.0',
496+
'172.16.0.1',
497+
'172.31.255.255',
498+
'192.168.0.0',
499+
'192.168.1.1',
500+
'192.168.255.255',
501+
]).forEach((topic) => {
502+
should.equal(topic.isPrivate(), true);
503+
});
504+
});
505+
506+
it('rejects non-private addresses including range boundaries', () => {
507+
notationsToAddresseses([
508+
'8.8.8.8',
509+
'9.255.255.255',
510+
'11.0.0.0',
511+
'172.15.255.255',
512+
'172.32.0.0',
513+
'192.167.255.255',
514+
'192.169.0.0',
515+
]).forEach((topic) => {
516+
should.equal(topic.isPrivate(), false);
517+
});
518+
});
519+
});
520+
521+
describe('isLoopback', () => {
522+
it('detects 127.0.0.0/8', () => {
523+
notationsToAddresseses(['127.0.0.0', '127.0.0.1', '127.255.255.255']).forEach((topic) => {
524+
should.equal(topic.isLoopback(), true);
525+
});
526+
});
527+
528+
it('rejects non-loopback addresses', () => {
529+
notationsToAddresseses(['126.255.255.255', '128.0.0.0', '8.8.8.8']).forEach((topic) => {
530+
should.equal(topic.isLoopback(), false);
531+
});
532+
});
533+
});
534+
535+
describe('isLinkLocal', () => {
536+
it('detects 169.254.0.0/16', () => {
537+
notationsToAddresseses(['169.254.0.0', '169.254.1.1', '169.254.255.255']).forEach((topic) => {
538+
should.equal(topic.isLinkLocal(), true);
539+
});
540+
});
541+
542+
it('rejects addresses outside 169.254.0.0/16', () => {
543+
notationsToAddresseses(['169.253.255.255', '169.255.0.0', '8.8.8.8']).forEach((topic) => {
544+
should.equal(topic.isLinkLocal(), false);
545+
});
546+
});
547+
});
548+
549+
describe('isUnspecified', () => {
550+
it('detects 0.0.0.0', () => {
551+
should.equal(new Address4('0.0.0.0').isUnspecified(), true);
552+
});
553+
554+
it('rejects non-zero addresses', () => {
555+
notationsToAddresseses(['0.0.0.1', '1.0.0.0', '8.8.8.8']).forEach((topic) => {
556+
should.equal(topic.isUnspecified(), false);
557+
});
558+
});
559+
});
560+
561+
describe('isBroadcast', () => {
562+
it('detects 255.255.255.255', () => {
563+
should.equal(new Address4('255.255.255.255').isBroadcast(), true);
564+
});
565+
566+
it('rejects non-broadcast addresses including subnet broadcasts', () => {
567+
notationsToAddresseses(['255.255.255.254', '192.168.1.255', '8.8.8.8']).forEach((topic) => {
568+
should.equal(topic.isBroadcast(), false);
569+
});
570+
});
571+
});
572+
573+
describe('isCGNAT', () => {
574+
it('detects 100.64.0.0/10', () => {
575+
notationsToAddresseses(['100.64.0.0', '100.64.0.1', '100.127.255.255']).forEach((topic) => {
576+
should.equal(topic.isCGNAT(), true);
577+
});
578+
});
579+
580+
it('rejects addresses outside 100.64.0.0/10', () => {
581+
notationsToAddresseses(['100.63.255.255', '100.128.0.0', '8.8.8.8']).forEach((topic) => {
582+
should.equal(topic.isCGNAT(), false);
583+
});
584+
});
585+
});
489586
});

‎test/functionality-v6-test.ts‎

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -871,6 +871,69 @@ describe('v6', () => {
871871
});
872872
});
873873

874+
describe('isULA', () => {
875+
it('detects fc00::/7', () => {
876+
notationsToAddresseses([
877+
'fc00::',
878+
'fc00::1',
879+
'fcff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',
880+
'fd00::',
881+
'fd12:3456:789a::1',
882+
'fdff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',
883+
]).forEach((topic) => {
884+
should.equal(topic.isULA(), true);
885+
});
886+
});
887+
888+
it('rejects addresses outside fc00::/7 including fe80::/10 and global unicast', () => {
889+
notationsToAddresseses([
890+
'::',
891+
'::1',
892+
'fbff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',
893+
'fe00::',
894+
'fe80::1',
895+
'2001:db8::1',
896+
]).forEach((topic) => {
897+
should.equal(topic.isULA(), false);
898+
});
899+
});
900+
});
901+
902+
describe('isUnspecified', () => {
903+
it('detects ::', () => {
904+
should.equal(new Address6('::').isUnspecified(), true);
905+
});
906+
907+
it('rejects non-zero addresses', () => {
908+
notationsToAddresseses(['::1', '2001:db8::1', 'fc00::']).forEach((topic) => {
909+
should.equal(topic.isUnspecified(), false);
910+
});
911+
});
912+
});
913+
914+
describe('isDocumentation', () => {
915+
it('detects 2001:db8::/32', () => {
916+
notationsToAddresseses([
917+
'2001:db8::',
918+
'2001:db8::1',
919+
'2001:db8:ffff:ffff:ffff:ffff:ffff:ffff',
920+
]).forEach((topic) => {
921+
should.equal(topic.isDocumentation(), true);
922+
});
923+
});
924+
925+
it('rejects addresses outside 2001:db8::/32', () => {
926+
notationsToAddresseses([
927+
'2001:db7:ffff:ffff:ffff:ffff:ffff:ffff',
928+
'2001:db9::',
929+
'2001::1',
930+
'fc00::',
931+
]).forEach((topic) => {
932+
should.equal(topic.isDocumentation(), false);
933+
});
934+
});
935+
});
936+
874937
describe('String helpers', () => {
875938
describe('spanLeadingZeroes', () => {
876939
it('should span leading zeroes', () => {

0 commit comments

Comments
 (0)