Created
February 21, 2018 20:51
-
-
Save codatory/ddf42bb0390708e47d3a8d801c2a2bcb to your computer and use it in GitHub Desktop.
Build CIDR lists of bad hosts
This file contains hidden or 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
#!/usr/local ruby | |
lists = { | |
blocklist_de: "https://lists.blocklist.de/lists/all.txt", | |
tor_exit: "https://www.dan.me.uk/torlist/?exit", | |
dshield: "http://feeds.dshield.org/block.txt", | |
spamhaus: "https://www.spamhaus.org/drop/drop.txt" | |
} | |
lists.each do |name,url| | |
`wget -NSO #{name}.txt #{url}` | |
end | |
export = File.new("export.txt", "w+") | |
File.read("dshield.txt").each_line do |line| | |
next if line.match(/^#/) | |
next if line.match(/^Start/) | |
next if line.match(/^[\da-fA-F]{4}:[\da-fA-F]{4}:/) | |
data = line.split("\t") | |
export << "#{data[0]}/#{data[2]}\n" | |
end | |
File.read("spamhaus.txt").each_line do |line| | |
next if line.match(/^;/) | |
next if line.match(/^[\da-fA-F]{4}:[\da-fA-F]{4}:/) | |
export << line.match(/(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\/\d{1,2}) ;.*$/)[1] | |
export << "\n" | |
end | |
['blocklist_de', 'tor_exit'].each do |file| | |
File.read("#{file}.txt").each_line do |line| | |
next if line.match(/^[\da-fA-F]{4}:[\da-fA-F]{4}:/) | |
export << "#{line.strip}/32\n" | |
end | |
end | |
export.close | |
`cat export.txt | aggregate > aggregated.txt` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment