Skip to content

Instantly share code, notes, and snippets.

@codatory
Created February 21, 2018 20:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save codatory/ddf42bb0390708e47d3a8d801c2a2bcb to your computer and use it in GitHub Desktop.
Save codatory/ddf42bb0390708e47d3a8d801c2a2bcb to your computer and use it in GitHub Desktop.
Build CIDR lists of bad hosts
#!/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