Created
April 15, 2015 17:05
-
-
Save ArkeologeN/771b75ad03bca18a2d10 to your computer and use it in GitHub Desktop.
AWS parsing
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
;(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