Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function getLowestIpRanges(ips) {
- let ipRanges = [];
- ips.forEach(x => {
- let x3 = x.replace(/\d+$/, '');
- let x2 = x3.replace(/\d+\.?$/, '');
- let x1 = x2.replace(/\d+\.?$/, '');
- let ex = ipRanges.filter(y => y == x3 + '0' || y == x2 + '0.0' || y == x1 + '0.0.0');
- if (ex.length) return;
- ex = ipRanges.filter(y => y.startsWith(x2));
- if (ex.length) {
- ipRanges.splice(ipRanges.indexOf(x[0]), 1)
- ipRanges.push(x2 + '0.0')
- } else {
- ex = ipRanges.filter(y => y.startsWith(x1));
- if (ex.length) {
- ipRanges.splice(ipRanges.indexOf(x[0]), 1)
- ipRanges.push(x1 + '0.0.0')
- } else {
- ipRanges.push(x3 + '0')
- }
- }
- });
- ipRanges = ipRanges.map(x => x.endsWith('.0.0.0') ? (x + '/8') : (x.endsWith('.0.0') ? (x + '/16') : (x + '/24')));
- return ipRanges;
- }
Add Comment
Please, Sign In to add comment