Skip to content

Instantly share code, notes, and snippets.

@mkyung
Forked from wbingli/aws_ips.rb
Created April 3, 2016 03:48
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
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