UNPKG

cloudscope

Version:

A Node.js library to detect whether an IP address belongs to a cloud provider. Supports AWS, Azure, GCP, Oracle, IBM, DigitalOcean, Linode, Exoscale, and Vultr. Fetches and normalizes CIDR ranges, then lets you check IPv4 and IPv6 addresses efficiently.

15 lines (12 loc) 341 B
const ipaddr = require('ipaddr.js'); function ipInCidr(ip, cidr) { try { const addr = ipaddr.parse(ip); const [rangeAddr, prefixLen] = ipaddr.parseCIDR(cidr); if (addr.kind() !== rangeAddr.kind()) return false; return addr.match([rangeAddr, prefixLen]); } catch { return false; } } module.exports = { ipInCidr };