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.

28 lines (27 loc) 955 B
const axios = require('axios') const papa = require('papaparse') module.exports = async function getDigitalOcean() { const ips = new Map() try { // Get the JSON data of IP ranges const csv = (await axios.get('https://digitalocean.com/geo/google.csv', { maxRedirects: 10 })).data const rows = papa.parse(csv).data for (const entry of rows) { if (ips.has(entry[3])) { entry[0].includes('.') ? ips.get(entry[3]).addressesv4.push(entry[0]) : ips.get(entry[3]).addressesv6.push(entry[0]) } else if (entry[3]) { ips.set(entry[3], { cloud: 'Digital Ocean', region: entry[3], regionId: entry[2], service: null, addressesv4: entry[0].includes('.') ? [entry[0]] : [], addressesv6: entry[0].includes(':') ? [entry[0]] : [] }) } } } catch (error) { console.error(`DigitalOcean error: ${error}`) } return Array.from(ips.values()) }