Skip to content

Instantly share code, notes, and snippets.

@jiphex
Created November 17, 2011 10:15
Show Gist options
  • Save jiphex/1372850 to your computer and use it in GitHub Desktop.
Save jiphex/1372850 to your computer and use it in GitHub Desktop.
Bruteforce multi DNS resolver
#!/usr/bin/env ruby
# DNS Bulk Resolver
#
# Resolves all the domains in the file argv[0], and www.$(each)
# Uses the resolv.conf file specified below (googledns.conf)
# Will hammer your DNS servers, be cautious.
# Creates a thread for each line in the file, be cautious.
# Be safe.
require 'resolv'
require 'pp'
$ips = {}
threads = []
def threaded_lookup(name)
# you may want to change what resolv conf you use.
goodns = Resolv::DNS.new(resolv_conf='/etc/resolv.conf')
t = Thread.new do
name.chomp!
begin
next if name == ""
next unless name
puts "checking [[[#{name}]]]"
ip = goodns.getaddress(name)
ip ||= goodns.getaddress("www.#{name}")
puts "#{name} resolves to #{ip}"
callback_with_ip(name,ip)
rescue Resolv::ResolvError
STDERR.puts "#{name} does not resolve"
rescue ArgumentError
redo
end
end
return t
end
def callback_with_ip(name,ip)
if $ips.has_key?(ip.to_s)
$ips[ip.to_s].push(name)
else
$ips[ip.to_s] = [name]
end
end
File.open(ARGV[0]).each_line do |line|
threads.push(threaded_lookup(line))
end
puts "#{threads.length} threads."
for t in threads
t.join()
end
# TODO: print something better
pp $ips
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment