Created
August 19, 2019 11:54
-
-
Save peterc/dd7173d1a13ac62c9e45a37141bf3868 to your computer and use it in GitHub Desktop.
Create UFW rules to block AWS regions and services
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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