ip-utilties 3.5.1 → 3.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/src/ip.mjs +32 -6
- package/types/ip.d.mts +41 -41
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ip-utilties",
|
|
3
|
-
"version": "3.5.
|
|
3
|
+
"version": "3.5.3",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public",
|
|
6
6
|
"provenance": true
|
|
@@ -41,11 +41,11 @@
|
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"ava": "^8.0.1",
|
|
44
|
-
"browser-ava": "^2.3.
|
|
44
|
+
"browser-ava": "^2.3.66",
|
|
45
45
|
"c8": "^11.0.0",
|
|
46
46
|
"documentation": "^14.0.3",
|
|
47
47
|
"semantic-release": "^25.0.5",
|
|
48
|
-
"typescript": "^
|
|
48
|
+
"typescript": "^7.0.2"
|
|
49
49
|
},
|
|
50
50
|
"overrides": {
|
|
51
51
|
"c8": {
|
package/src/ip.mjs
CHANGED
|
@@ -22,10 +22,24 @@ const ipv4 = {
|
|
|
22
22
|
linkLocalPrefixLength: 16,
|
|
23
23
|
localHost: new Uint8Array([127, 0, 0, 1]),
|
|
24
24
|
localHostPrefixLenth: 8,
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
[new Uint8Array([
|
|
25
|
+
|
|
26
|
+
// https://www.geeksforgeeks.org/computer-networks/subnet-cheat-sheet/
|
|
27
|
+
wellKnownAddresses: [
|
|
28
|
+
[new Uint8Array([0, 0, 0, 0]), 8], // This network
|
|
29
|
+
[new Uint8Array([10, 0, 0, 0]), 8], // Private network (RFC 1918)
|
|
30
|
+
[new Uint8Array([100, 64, 0, 0]), 10], // Carrier-grade NAT / Shared address space (CGN)
|
|
31
|
+
[new Uint8Array([127, 0, 0, 0]), 8], // Loopback
|
|
32
|
+
[new Uint8Array([127, 0, 53, 53]), 0], // Name collision occurrence
|
|
33
|
+
[new Uint8Array([169, 254, 0, 0]), 16], // Link-local address (Autoconfiguration)
|
|
34
|
+
[new Uint8Array([172, 16, 0, 0]), 12], // Private network (RFC 1918)
|
|
35
|
+
[new Uint8Array([192, 0, 0, 0]), 24], // IETF protocol assignments
|
|
36
|
+
[new Uint8Array([192, 0, 2, 0]), 24], // TEST-NET-1
|
|
37
|
+
[new Uint8Array([192, 168, 0, 0]), 16], // Private network (RFC 1918)
|
|
38
|
+
[new Uint8Array([198, 18, 0, 0]), 15], // Network benchmark testing
|
|
39
|
+
[new Uint8Array([198, 51, 100, 0]), 24], // TEST-NET-2
|
|
40
|
+
[new Uint8Array([203, 0, 113, 0]), 24], // Reserved address space used for documentation
|
|
41
|
+
[new Uint8Array([240, 0, 0, 0]), 4], // Reserved for future use or experimental purposes
|
|
42
|
+
[new Uint8Array([255, 255, 255, 255]), 0] // Limited Broadcast address
|
|
29
43
|
]
|
|
30
44
|
};
|
|
31
45
|
|
|
@@ -400,8 +414,20 @@ export function _wellKnownSubnet(family, address) {
|
|
|
400
414
|
}
|
|
401
415
|
|
|
402
416
|
if (family === ipv4) {
|
|
403
|
-
for (const c of family.
|
|
404
|
-
|
|
417
|
+
for (const c of family.wellKnownAddresses) {
|
|
418
|
+
const pl = c[1];
|
|
419
|
+
if (
|
|
420
|
+
pl > 0 &&
|
|
421
|
+
_prefix(family, c[0], pl) === _prefix(family, encoded, pl)
|
|
422
|
+
) {
|
|
423
|
+
/*console.log(
|
|
424
|
+
c,
|
|
425
|
+
encoded,
|
|
426
|
+
_prefix(family, c[0], pl),
|
|
427
|
+
_prefix(family, encoded, pl),
|
|
428
|
+
prefixIP(c[0], pl),
|
|
429
|
+
prefixIP(encoded, pl)
|
|
430
|
+
);*/
|
|
405
431
|
return c;
|
|
406
432
|
}
|
|
407
433
|
}
|
package/types/ip.d.mts
CHANGED
|
@@ -1,66 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Address familiy IPv4
|
|
3
|
+
*/
|
|
4
|
+
export declare const FAMILY_IPV4 = "IPv4";
|
|
5
|
+
/**
|
|
6
|
+
* Address familiy IPv6
|
|
7
|
+
*/
|
|
8
|
+
export declare const FAMILY_IPV6 = "IPv6";
|
|
1
9
|
/**
|
|
2
10
|
* Encode ipv4 or ipv6 address into number array.
|
|
3
11
|
* @param {string|number[]} address
|
|
4
12
|
* @returns number[]
|
|
5
13
|
*/
|
|
6
|
-
export function encodeIP(address: string | number[]): any;
|
|
14
|
+
export declare function encodeIP(address: string | number[]): any;
|
|
7
15
|
/**
|
|
8
16
|
* Encode ipv6 address into number array.
|
|
9
17
|
* @param {string|number[]|bigint} address
|
|
10
18
|
* @returns number[]
|
|
11
19
|
*/
|
|
12
|
-
export function encodeIPv6(address: string | number[] | bigint): any;
|
|
20
|
+
export declare function encodeIPv6(address: string | number[] | bigint): any;
|
|
13
21
|
/**
|
|
14
22
|
* Encode ipv4 address into number array.
|
|
15
23
|
* @param {string|number[]|bigint} address
|
|
16
24
|
* @returns number[]
|
|
17
25
|
*/
|
|
18
|
-
export function encodeIPv4(address: string | number[] | bigint): any;
|
|
19
|
-
export function decodeIPv6(address: any, length: any): string;
|
|
20
|
-
export function decodeIPv4(address: any, length: any): string;
|
|
21
|
-
export function decodeIP(address: any, length: any): string;
|
|
22
|
-
export function isIPv4(address: any): boolean;
|
|
23
|
-
export function isIPv6(address: any): boolean;
|
|
26
|
+
export declare function encodeIPv4(address: string | number[] | bigint): any;
|
|
27
|
+
export declare function decodeIPv6(address: any, length: any): string;
|
|
28
|
+
export declare function decodeIPv4(address: any, length: any): string;
|
|
29
|
+
export declare function decodeIP(address: any, length: any): string;
|
|
30
|
+
export declare function isIPv4(address: any): boolean;
|
|
31
|
+
export declare function isIPv6(address: any): boolean;
|
|
24
32
|
/**
|
|
25
33
|
* IP address family for a given address.
|
|
26
34
|
* @param {string|Uint8Array|Uint16Array} address
|
|
27
35
|
* @return {string|undefined}
|
|
28
36
|
*/
|
|
29
|
-
export function familyIP(address: string | Uint8Array | Uint16Array): string | undefined;
|
|
30
|
-
export function asBigInt(address: any): any;
|
|
31
|
-
export function prefixIP(address: any, length: any): string;
|
|
32
|
-
export function rangeIP(address: any, prefix: any, lowerAdd?: number, upperReduce?: number): any[];
|
|
33
|
-
export function matchPrefixIP(prefix: any, length: any, address: any): boolean;
|
|
34
|
-
export function normalizeCIDR(address: any): {
|
|
37
|
+
export declare function familyIP(address: string | Uint8Array | Uint16Array): string | undefined;
|
|
38
|
+
export declare function asBigInt(address: any): any;
|
|
39
|
+
export declare function prefixIP(address: any, length: any): string;
|
|
40
|
+
export declare function rangeIP(address: any, prefix: any, lowerAdd?: number, upperReduce?: number): any[];
|
|
41
|
+
export declare function matchPrefixIP(prefix: any, length: any, address: any): boolean;
|
|
42
|
+
export declare function normalizeCIDR(address: any): {
|
|
35
43
|
longPrefix: any;
|
|
36
44
|
prefix: any;
|
|
37
45
|
prefixLength: any;
|
|
38
46
|
cidr: string;
|
|
39
47
|
};
|
|
40
|
-
export function formatCIDR(address: any, prefixLength: any): any;
|
|
41
|
-
export function normalizeIP(address: any): string | undefined;
|
|
42
|
-
export function reverseArpa(address: any): string;
|
|
43
|
-
export function isLocalhost(address: any): boolean;
|
|
44
|
-
export function isLinkLocal(address: any): boolean;
|
|
45
|
-
export function _isLinkLocal(family: any, address: any): boolean;
|
|
46
|
-
export function isUniqueLocal(address: any): boolean;
|
|
47
|
-
export function _isUniqueLocal(eaddr: any): boolean;
|
|
48
|
-
export function hasWellKnownSubnet(address: any): boolean;
|
|
49
|
-
export function wellKnownSubnet(address: any): any;
|
|
50
|
-
export function _wellKnownSubnet(family: any, address: any): any;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
export const
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
export const
|
|
59
|
-
export const IPV6_NODE_LOCAL_ALL_NODES: any;
|
|
60
|
-
export const IPV6_NODE_LOCAL_ALL_ROUTERS: any;
|
|
61
|
-
export const IPV6_LINK_LOCAL_ALL_NODES: any;
|
|
62
|
-
export const IPV6_LINK_LOCAL_ALL_ROUTERS: any;
|
|
63
|
-
export const IPV6_SITE_LOCAL_ALL_ROUTERS: any;
|
|
64
|
-
export const IPV6_SITE_LOCAL_ALL_DHCP_SERVERS: any;
|
|
65
|
-
export const IPV4_LOCALHOST: Uint8Array<ArrayBuffer>;
|
|
66
|
-
export const IPV6_LOCALHOST: Uint16Array<ArrayBuffer>;
|
|
48
|
+
export declare function formatCIDR(address: any, prefixLength: any): any;
|
|
49
|
+
export declare function normalizeIP(address: any): string | undefined;
|
|
50
|
+
export declare function reverseArpa(address: any): string;
|
|
51
|
+
export declare function isLocalhost(address: any): boolean;
|
|
52
|
+
export declare function isLinkLocal(address: any): boolean;
|
|
53
|
+
export declare function _isLinkLocal(family: any, address: any): boolean;
|
|
54
|
+
export declare function isUniqueLocal(address: any): boolean;
|
|
55
|
+
export declare function _isUniqueLocal(eaddr: any): boolean;
|
|
56
|
+
export declare function hasWellKnownSubnet(address: any): boolean;
|
|
57
|
+
export declare function wellKnownSubnet(address: any): any;
|
|
58
|
+
export declare function _wellKnownSubnet(family: any, address: any): any;
|
|
59
|
+
export declare const IPV6_NODE_LOCAL_ALL_NODES: any;
|
|
60
|
+
export declare const IPV6_NODE_LOCAL_ALL_ROUTERS: any;
|
|
61
|
+
export declare const IPV6_LINK_LOCAL_ALL_NODES: any;
|
|
62
|
+
export declare const IPV6_LINK_LOCAL_ALL_ROUTERS: any;
|
|
63
|
+
export declare const IPV6_SITE_LOCAL_ALL_ROUTERS: any;
|
|
64
|
+
export declare const IPV6_SITE_LOCAL_ALL_DHCP_SERVERS: any;
|
|
65
|
+
export declare const IPV4_LOCALHOST: Uint8Array<ArrayBuffer>;
|
|
66
|
+
export declare const IPV6_LOCALHOST: Uint16Array<ArrayBuffer>;
|