Script to process all apache config files and confirm configuration of DNS and Hosting

require “resolv”
require ‘whois’

files = File.read(“domains.txt”)
files = files.split(“\n”)
w = Whois::Client.new

result = “”
files.each do |file|
ip = Resolv.getaddress(file) rescue “”
if ip != “”

ip_whois = w.lookup(ip).content.split(“\n”).select { |string| string.include?(“NetName”) }.to_s.gsub(” “,””).gsub(“NetName:”,””)
domain_whois = w.lookup(file).nameservers.join(‘, ‘) rescue ” ”

puts ip_whois
puts domain_whois
result = result + “\n” + ip + “, ” + file + “, ” + ip_whois + “, ” + domain_whois
puts result + “\n” + ip + “, ” + file + “, ” + ip_whois + “, ” + domain_whois

puts

end
end

File.write(‘resolved_domains.csv’, result)