Skip to content

Instantly share code, notes, and snippets.

@thejefflarson
Created June 22, 2016 00:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thejefflarson/42273cbe9d059051df4e847b3cb7a31c to your computer and use it in GitHub Desktop.
Save thejefflarson/42273cbe9d059051df4e847b3cb7a31c to your computer and use it in GitHub Desktop.
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