Last active
June 17, 2019 08:04
-
-
Save bennettp123/29cc4eee92b447b9bf368d34166b066e to your computer and use it in GitHub Desktop.
Deduplicate and compress CIDRs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const cidrTools = require('cidr-tools'); | |
const readline = require('readline'); | |
const JSON = require('JSON'); | |
const rl = readline.createInterface({ | |
input: process.stdin, | |
output: process.stdout, | |
crlfDelay: Infinity | |
}); | |
let cidrs = []; | |
rl.on('line', (line) => { | |
cidrs = cidrTools.merge(cidrs.concat(line)); | |
}); | |
rl.on('close', () => { | |
console.log(JSON.stringify(cidrs)); | |
}); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "compress-cidrs", | |
"version": "1.0.0", | |
"lockfileVersion": 1, | |
"requires": true, | |
"dependencies": { | |
"JSON": { | |
"version": "1.0.0", | |
"resolved": "https://registry.npmjs.org/JSON/-/JSON-1.0.0.tgz", | |
"integrity": "sha1-hoFTHCj4Q4oHVYn/BySCRuqWDYw=" | |
}, | |
"cidr-regex": { | |
"version": "2.0.10", | |
"resolved": "https://registry.npmjs.org/cidr-regex/-/cidr-regex-2.0.10.tgz", | |
"integrity": "sha512-sB3ogMQXWvreNPbJUZMRApxuRYd+KoIo4RGQ81VatjmMW6WJPo+IJZ2846FGItr9VzKo5w7DXzijPLGtSd0N3Q==", | |
"requires": { | |
"ip-regex": "^2.1.0" | |
} | |
}, | |
"cidr-tools": { | |
"version": "2.2.8", | |
"resolved": "https://registry.npmjs.org/cidr-tools/-/cidr-tools-2.2.8.tgz", | |
"integrity": "sha512-A/xvQXULkINGWhm1FCMsZdvWLmekoea/ydOijiVpWVC4jNfSsXevdRqingdtOz2s6it57NKc4byPgyQEwwSFrw==", | |
"requires": { | |
"ip-address": "^5.9.0", | |
"ip-cidr": "^2.0.2", | |
"ipv6-normalize": "^1.0.1", | |
"is-cidr": "^3.0.0", | |
"jsbn": "^1.1.0", | |
"string-natural-compare": "^2.0.3" | |
} | |
}, | |
"ip-address": { | |
"version": "5.9.2", | |
"resolved": "https://registry.npmjs.org/ip-address/-/ip-address-5.9.2.tgz", | |
"integrity": "sha512-7aeFm/7oqo0mMhubTSjZ2Juw/F+WJ3hyfCScNVRQdz5RSRhw1Rj4ZlBFsmEajeKgQDI8asqVs31h8DpxEv7IfQ==", | |
"requires": { | |
"jsbn": "1.1.0", | |
"lodash": "^4.17.11", | |
"sprintf-js": "1.1.2" | |
} | |
}, | |
"ip-cidr": { | |
"version": "2.0.2", | |
"resolved": "https://registry.npmjs.org/ip-cidr/-/ip-cidr-2.0.2.tgz", | |
"integrity": "sha512-4S23kpi6/vLp7fGBYFZKCxhdZZUkGxptIn5TqohnUexqMrbS1eGnveRXJarlUl6lQSgGsN9GQ7xqIPGyme/M3g==", | |
"requires": { | |
"ip-address": "^5.8.6", | |
"jsbn": "^0.1.0" | |
}, | |
"dependencies": { | |
"jsbn": { | |
"version": "0.1.1", | |
"resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz", | |
"integrity": "sha1-peZUwuWi3rXyAdls77yoDA7y9RM=" | |
} | |
} | |
}, | |
"ip-regex": { | |
"version": "2.1.0", | |
"resolved": "https://registry.npmjs.org/ip-regex/-/ip-regex-2.1.0.tgz", | |
"integrity": "sha1-+ni/XS5pE8kRzp+BnuUUa7bYROk=" | |
}, | |
"ipv6-normalize": { | |
"version": "1.0.1", | |
"resolved": "https://registry.npmjs.org/ipv6-normalize/-/ipv6-normalize-1.0.1.tgz", | |
"integrity": "sha1-GzJYKQ02X6gyOeiZB93kWS52IKg=" | |
}, | |
"is-cidr": { | |
"version": "3.0.0", | |
"resolved": "https://registry.npmjs.org/is-cidr/-/is-cidr-3.0.0.tgz", | |
"integrity": "sha512-8Xnnbjsb0x462VoYiGlhEi+drY8SFwrHiSYuzc/CEwco55vkehTaxAyIjEdpi3EMvLPPJAJi9FlzP+h+03gp0Q==", | |
"requires": { | |
"cidr-regex": "^2.0.10" | |
} | |
}, | |
"jsbn": { | |
"version": "1.1.0", | |
"resolved": "https://registry.npmjs.org/jsbn/-/jsbn-1.1.0.tgz", | |
"integrity": "sha1-sBMHyym2GKHtJux56RH4A8TaAEA=" | |
}, | |
"lodash": { | |
"version": "4.17.11", | |
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz", | |
"integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==" | |
}, | |
"sprintf-js": { | |
"version": "1.1.2", | |
"resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.1.2.tgz", | |
"integrity": "sha512-VE0SOVEHCk7Qc8ulkWw3ntAzXuqf7S2lvwQaDLRnUeIEaKNQJzV6BwmLKhOqT61aGhfUMrXeaBk+oDGCzvhcug==" | |
}, | |
"string-natural-compare": { | |
"version": "2.0.3", | |
"resolved": "https://registry.npmjs.org/string-natural-compare/-/string-natural-compare-2.0.3.tgz", | |
"integrity": "sha512-4Kcl12rNjc+6EKhY8QyDVuQTAlMWwRiNbsxnVwBUKFr7dYPQuXVrtNU4sEkjF9LHY0AY6uVbB3ktbkIH4LC+BQ==" | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "compress-cidrs", | |
"version": "1.0.0", | |
"description": "Deduplicate and remove overlapping CIDRs", | |
"main": "compress-cidrs.js", | |
"scripts": { | |
"test": "whois -h whois.radb.net -- '-i origin AS32934' | grep ^route | awk '{print $2}' | node compress-cidrs.js" | |
}, | |
"author": "Bennett Perkins <bennett.perkins@wanews.com.au>", | |
"license": "ISC", | |
"dependencies": { | |
"JSON": "^1.0.0", | |
"cidr-tools": "^2.2.8" | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment