Skip to content

Instantly share code, notes, and snippets.

@peterc
Created August 19, 2019 11:54
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 peterc/dd7173d1a13ac62c9e45a37141bf3868 to your computer and use it in GitHub Desktop.
Save peterc/dd7173d1a13ac62c9e45a37141bf3868 to your computer and use it in GitHub Desktop.
Create UFW rules to block AWS regions and services
require 'json'
require 'open-uri'
URL = "https://ip-ranges.amazonaws.com/ip-ranges.json"
REGION = "us-east"
SERVICE = "EC2"
j = JSON.parse(open(URL).read)
j['prefixes'].select { |k| k['region'].start_with?(REGION) && k['service'] == SERVICE }.each do |l|
puts "ufw deny from #{l['ip_prefix']}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment