|
1 | 1 | import { IPMatcher } from "../../helpers/ip-matcher/IPMatcher"; |
| 2 | +import mapIPv4ToIPv6 from "../../helpers/mapIPv4ToIPv6"; |
2 | 3 |
|
3 | | -// Taken from https://github.com/frenchbread/private-ip/blob/master/src/index.ts |
4 | 4 | const PRIVATE_IP_RANGES = [ |
5 | | - "0.0.0.0/8", |
6 | | - "10.0.0.0/8", |
7 | | - "100.64.0.0/10", |
8 | | - "127.0.0.0/8", |
9 | | - "169.254.0.0/16", |
10 | | - "172.16.0.0/12", |
11 | | - "192.0.0.0/24", |
12 | | - "192.0.2.0/24", |
13 | | - "192.31.196.0/24", |
14 | | - "192.52.193.0/24", |
15 | | - "192.88.99.0/24", |
16 | | - "192.168.0.0/16", |
17 | | - "192.175.48.0/24", |
18 | | - "198.18.0.0/15", |
19 | | - "198.51.100.0/24", |
20 | | - "203.0.113.0/24", |
21 | | - "240.0.0.0/4", |
22 | | - "224.0.0.0/4", |
23 | | - "255.255.255.255/32", |
| 5 | + "0.0.0.0/8", // "This" network (RFC 1122) |
| 6 | + "10.0.0.0/8", // Private-Use Networks (RFC 1918) |
| 7 | + "100.64.0.0/10", // Shared Address Space (RFC 6598) |
| 8 | + "127.0.0.0/8", // Loopback (RFC 1122) |
| 9 | + "169.254.0.0/16", // Link Local (RFC 3927) |
| 10 | + "172.16.0.0/12", // Private-Use Networks (RFC 1918) |
| 11 | + "192.0.0.0/24", // IETF Protocol Assignments (RFC 5736) |
| 12 | + "192.0.2.0/24", // TEST-NET-1 (RFC 5737) |
| 13 | + "192.31.196.0/24", // AS112 Redirection Anycast (RFC 7535) |
| 14 | + "192.52.193.0/24", // Automatic Multicast Tunneling (RFC 7450) |
| 15 | + "192.88.99.0/24", // 6to4 Relay Anycast (RFC 3068) |
| 16 | + "192.168.0.0/16", // Private-Use Networks (RFC 1918) |
| 17 | + "192.175.48.0/24", // AS112 Redirection Anycast (RFC 7535) |
| 18 | + "198.18.0.0/15", // Network Interconnect Device Benchmark Testing (RFC 2544) |
| 19 | + "198.51.100.0/24", // TEST-NET-2 (RFC 5737) |
| 20 | + "203.0.113.0/24", // TEST-NET-3 (RFC 5737) |
| 21 | + "224.0.0.0/4", // Multicast (RFC 3171) |
| 22 | + "240.0.0.0/4", // Reserved for Future Use (RFC 1112) |
| 23 | + "255.255.255.255/32", // Limited Broadcast (RFC 919) |
24 | 24 | ]; |
25 | 25 |
|
26 | 26 | const PRIVATE_IPV6_RANGES = [ |
27 | | - "::/128", // Unspecified address |
28 | | - "::1/128", // Loopback address |
29 | | - "fc00::/7", // Unique local address (ULA) |
30 | | - "fe80::/10", // Link-local address (LLA) |
31 | | - "::ffff:127.0.0.1/128", // IPv4-mapped address |
32 | | - "::ffff:0:0", |
33 | | -]; |
| 27 | + "::/128", // Unspecified address (RFC 4291) |
| 28 | + "::1/128", // Loopback address (RFC 4291) |
| 29 | + "fc00::/7", // Unique local address (ULA) (RFC 4193) |
| 30 | + "fe80::/10", // Link-local address (LLA) (RFC 4291) |
| 31 | + "100::/64", // Discard prefix (RFC 6666) |
| 32 | + "2001:db8::/32", // Documentation prefix (RFC 3849) |
| 33 | + "3fff::/20", // Documentation prefix (RFC 9637) |
| 34 | +].concat( |
| 35 | + // Add the IPv4-mapped IPv6 addresses |
| 36 | + PRIVATE_IP_RANGES.map(mapIPv4ToIPv6) |
| 37 | +); |
34 | 38 |
|
35 | 39 | const privateIp = new IPMatcher(); |
36 | 40 |
|
|
0 commit comments