Skip to content

Instantly share code, notes, and snippets.

Created February 28, 2016 19:27
Show Gist options
  • Save anonymous/0ac2c8dc1bf5ce2100df to your computer and use it in GitHub Desktop.
Save anonymous/0ac2c8dc1bf5ce2100df 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
ip = Resolv.getaddress h
points = resolvs[ip]
if points.nil? || /\d+\.\d+\.\d+\.\d+/.match(points)
resolvs[ip] = h
end
end
end
ips = []
groups = {}
resolvs.each do |ip, h|
if ip == h
ips << hosts[h]
else
domain = h.split(/\./)
domain = domain.size > 2 ? domain[1] : domain[0]
if groups[domain]. nil?
groups[domain] = [hosts[h]]
else
groups[domain] << hosts[h]
end
end
end
groups.each do |group, uris|
uris.each{ |uri| puts uri }
puts "\n"
end
ips.each do |ip|
puts ip
puts "\n"
end
@andresperezl
Copy link

I forgot to login before creating this GIst

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment