Skip to content

Instantly share code, notes, and snippets.

@wbingli
Created October 28, 2015 20:49
Show Gist options
  • Save wbingli/d903ee7e059d5b742f96 to your computer and use it in GitHub Desktop.
Save wbingli/d903ee7e059d5b742f96 to your computer and use it in GitHub Desktop.
Calculate AWS total IPs
require 'open-uri'
require 'json'
data = JSON.load(open("https://ip-ranges.amazonaws.com/ip-ranges.json"))
ip_total = data['prefixes'].reduce(0) do | sum, item |
sum += 2 ** (32 - item['ip_prefix'].split('/')[1].to_i)
end
puts "AWS Total IPs: #{ip_total}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment