Skip to content

Instantly share code, notes, and snippets.

@creadone
Created April 27, 2021 22:55
Show Gist options
  • Save creadone/7e7423837da610115b9077cee983f2c1 to your computer and use it in GitHub Desktop.
Save creadone/7e7423837da610115b9077cee983f2c1 to your computer and use it in GitHub Desktop.
require 'json'
require 'dnsruby'
include Dnsruby
REC_TYPES = %w(A AAAA NS CNAME MX PTR TXT SOA SPF)
DEA_HOSTS = File.open('hosts.csv', 'r')
RESOLVER = Resolver.new
TMP_STORE = {}
def fetch_record(host, type)
result = RESOLVER.query(host, type)
{ type => result.answer.map(&:to_s) }
end
DEA_HOSTS.each_line do |line|
host = line.strip
records = REC_TYPES.map{ |type| fetch_record(host, type) }
TMP_STORE[host] = records
rescue => e
puts "#{host}: #{e.message}"
end
File.open('output.json', 'w') do |io|
io << JSON.pretty_generate(TMP_STORE)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment