Skip to content

Instantly share code, notes, and snippets.

@andresperezl
Forked from anonymous/trackers-resolvs.rb
Last active September 5, 2018 02:03
Show Gist options
  • Save andresperezl/9f187d378aed457a7759 to your computer and use it in GitHub Desktop.
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.
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