Skip to content

Instantly share code, notes, and snippets.

@richorama
Created August 4, 2014 09:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save richorama/53b7285398f89308f55d to your computer and use it in GitHub Desktop.
Save richorama/53b7285398f89308f55d to your computer and use it in GitHub Desktop.
Count the public IP addresses in each of the Azure DCs
var xml2js = require('xml2js');
var fs = require('fs');
var Netmask = require('netmask').Netmask;
// download from here http://www.microsoft.com/en-gb/download/details.aspx?id=41653
var xml = fs.readFileSync('ip-ranges.xml').toString();
xml2js.parseString(xml, function(err, json){
var output = {};
var total = 0;
json.AzurePublicIpAddresses.Region.forEach(function(x){
output[x.$.Name] = 0;
x.IpRange.forEach(function(z){
var block = new Netmask(z.$.Subnet);
//console.log(block);
output[x.$.Name] += block.size;
total += block.size;
});
});
console.log(output)
console.log(total)
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment