Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
require 'resolv'
require 'thread'
require 'csv'
require 'set'
ALPHABET = ('a'..'z').to_a + ('0'..'9').to_a + ['-']
def convert(num)
return ALPHABET[0] if num == 0
base = ALPHABET.length
converted = []
until num.zero?
num, digit = num.divmod(base)
converted.push(ALPHABET[digit])
end
converted.reverse.join
end
s = Set.new
CSV.foreach('./official-list.csv', :headers => true) do |row|
s << row['Domain Name'].downcase
end
q = Queue.new
lock = Mutex.new
out = open('out-alpha.txt', 'a')
workers = (1..100).map do
Thread.new do
loop do
name = q.pop
Resolv::DNS.new.each_address(name) do |addr|
lock.synchronize { out.puts "#{name}, #{addr}"; out.flush }
end
end
end
end
t = Time.now
i = start = 185357051
up = false
loop do
name = convert(i)
i += 1
next if name[0] == '-' || name[-1] == '-'
name = name + '.gov'
next if s.include? name
q << name
sleep(1) while q.length > 100
print "processed a second: #{((i - start).to_f / (Time.now - t)).to_i} currently: #{name}, #{i} \r"
end
workers.map(&:join)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment