Skip to content

Instantly share code, notes, and snippets.

@analogrithems
Last active January 13, 2016 19:36
Show Gist options
  • Save analogrithems/bf13b57275ed2f157daa to your computer and use it in GitHub Desktop.
Save analogrithems/bf13b57275ed2f157daa to your computer and use it in GitHub Desktop.
Generate an Nginx Geo list of Amazon IP's from their public JSON list
var jq = document.createElement('script');
jq.src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js";
document.getElementsByTagName('head')[0].appendChild(jq);
setTimeout(function(){
var jqxhr = jQuery.get( "https://ip-ranges.amazonaws.com/ip-ranges.json", function(data) {
var s = "geo $amazon {\n";
var ni = [];
s += "\tdefault\t\t\t0;\n";
for( var bean=0;bean<data.prefixes.length;bean++){
var ipb = data.prefixes[bean]['ip_prefix'];
#No dupes
if(!ni[ipb]){
s += "\t"+ipb+"\t\t\t1;\n"
ni[ipb]=1;
}
}
s += "}\n";
console.log(s);
})
}, 3000);
@analogrithems
Copy link
Author

To use this, go to https://ip-ranges.amazonaws.com/ip-ranges.json open chrome console and just paste it in

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment