Skip to content

Instantly share code, notes, and snippets.

@mkyung
Forked from wbingli/aws_ips.rb
Created April 3, 2016 03:48
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 mkyung/92a0db55af3c8e74286eedc93c289a50 to your computer and use it in GitHub Desktop.
Save mkyung/92a0db55af3c8e74286eedc93c289a50 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