Skip to content

Instantly share code, notes, and snippets.

@ArkeologeN
Created April 15, 2015 17:05
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 ArkeologeN/771b75ad03bca18a2d10 to your computer and use it in GitHub Desktop.
Save ArkeologeN/771b75ad03bca18a2d10 to your computer and use it in GitHub Desktop.
AWS parsing
;(function() {
'use strict';
var http = require('https');
var map = {
"ap-northeast-1": "Tokyo, JP",
"ap-southeast-1": "SG",
"ap-southeast-2": "Sydney, AU",
"eu-central-1": "Frankfurt, DE",
"eu-west-1": "IE",
"sa-east-1": "Sao Paulo, BR",
"us-east-1": "VA, US",
"us-west-1": "CA, US",
"us-west-2": "OR, UA"
};
http.get('https://ip-ranges.amazonaws.com/ip-ranges.json', function(res) {
var chunk = '';
res.on('data', function(data) {
chunk += data;
});
res.on('end', function() {
chunk = chunk.toString();
var records = JSON.parse(chunk),
csv = '';
[].concat(records.prefixes).forEach(function(prefix, key) {
var region = '"' + (map[prefix.region] || '') + '"',
mash = [prefix.ip_prefix, region];
csv += mash.toString() + "\n";
});
console.log(csv);
});
}).on('error', function(e) {
console.log(e.message);
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment