-
-
Save andresperezl/9f187d378aed457a7759 to your computer and use it in GitHub Desktop.
Little script that you feed a list of trackers and will eliminate the duplicates that point to the same IP addresses and try to group the trackers by domain name.
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 'uri' | |
require 'resolv' | |
text = File.open("trackers.txt").read.split(/\n|(\r\n)/) | |
hosts = text.map{ |uri| [URI(uri).host, uri] }.to_h | |
resolvs = {} | |
hosts.each do |h, uri| | |
if /\d+\.\d+\.\d+\.\d+/.match(h) | |
resolvs[h] = h | |
else | |
begin | |
ip = Resolv.getaddress h | |
points = resolvs[ip] | |
if points.nil? || /\d+\.\d+\.\d+\.\d+/.match(points) | |
resolvs[ip] = h | |
end | |
rescue | |
#Could not resolve address | |
end | |
end | |
end | |
schemes = ["udp", "http", "https"] | |
ips = { "udp" => [], "http" => [], "https" => [] } | |
groups = {} | |
resolvs.each do |ip, h| | |
scheme = URI(hosts[h]).scheme | |
if ip == h | |
ips[scheme] << hosts[h] | |
else | |
domain = h.split(/\./) | |
domain = domain.size > 2 ? domain[1] : domain[0] | |
if groups[domain].nil? | |
groups[domain] = { "udp" => [], "http" => [], "https" => [] } | |
end | |
groups[domain][scheme] << hosts[h] | |
end | |
end | |
groups.each do |group, uris| | |
schemes.each do |scheme| | |
uris[scheme].each{ |uri| puts uri } | |
end | |
puts "\n" | |
end | |
schemes.each do |scheme| | |
ips[scheme].each do |ip| | |
puts ip | |
puts "\n" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment