MCPcopy Index your code
hub / github.com/nodejs/node / #parseIPInfo

Method #parseIPInfo

lib/internal/blocklist.js:167–235  ·  view source on GitHub ↗
(data)

Source from the content-addressed store, hash-verified

165 * ];
166 */
167 #parseIPInfo(data) {
168 for (const item of data) {
169 if (item.includes('IPv4')) {
170 const subnetMatch = item.match(
171 /Subnet: IPv4 (\d{1,3}(?:\.\d{1,3}){3})\/(\d{1,2})/,
172 );
173 if (subnetMatch) {
174 const { 1: network, 2: prefix } = subnetMatch;
175 this.addSubnet(network, NumberParseInt(prefix));
176 continue;
177 }
178 const addressMatch = item.match(/Address: IPv4 (\d{1,3}(?:\.\d{1,3}){3})/);
179 if (addressMatch) {
180 const { 1: address } = addressMatch;
181 this.addAddress(address);
182 continue;
183 }
184
185 const rangeMatch = item.match(
186 /Range: IPv4 (\d{1,3}(?:\.\d{1,3}){3})-(\d{1,3}(?:\.\d{1,3}){3})/,
187 );
188 if (rangeMatch) {
189 const { 1: start, 2: end } = rangeMatch;
190 this.addRange(start, end);
191 continue;
192 }
193 }
194 // IPv6 parsing with support for compressed addresses
195 if (item.includes('IPv6')) {
196 // IPv6 subnet pattern: supports both full and compressed formats
197 // Examples:
198 // - 2001:0db8:85a3:0000:0000:8a2e:0370:7334/64 (full)
199 // - 2001:db8:85a3::8a2e:370:7334/64 (compressed)
200 // - 2001:db8:85a3::192.0.2.128/64 (mixed)
201 const ipv6SubnetMatch = item.match(
202 /Subnet: IPv6 ([0-9a-fA-F:]{1,39})\/([0-9]{1,3})/i,
203 );
204 if (ipv6SubnetMatch) {
205 const { 1: network, 2: prefix } = ipv6SubnetMatch;
206 this.addSubnet(network, NumberParseInt(prefix), 'ipv6');
207 continue;
208 }
209
210 // IPv6 address pattern: supports both full and compressed formats
211 // Examples:
212 // - 2001:0db8:85a3:0000:0000:8a2e:0370:7334 (full)
213 // - 2001:db8:85a3::8a2e:370:7334 (compressed)
214 // - 2001:db8:85a3::192.0.2.128 (mixed)
215 const ipv6AddressMatch = item.match(/Address: IPv6 ([0-9a-fA-F:]{1,39})/i);
216 if (ipv6AddressMatch) {
217 const { 1: address } = ipv6AddressMatch;
218 this.addAddress(address, 'ipv6');
219 continue;
220 }
221
222 // IPv6 range pattern: supports both full and compressed formats
223 // Examples:
224 // - 2001:0db8:85a3:0000:0000:8a2e:0370:7334-2001:0db8:85a3:0000:0000:8a2e:0370:7335 (full)

Callers 1

fromJSONMethod · 0.95

Calls 5

addSubnetMethod · 0.95
addAddressMethod · 0.95
addRangeMethod · 0.95
includesMethod · 0.80
matchMethod · 0.65

Tested by

no test coverage detected