Created
April 27, 2021 22:55
-
-
Save creadone/7e7423837da610115b9077cee983f2c1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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