Skip to content

Instantly share code, notes, and snippets.

@Fercell
Created February 4, 2015 10:02
Show Gist options
  • Save Fercell/a6e039d1e4babcefbada to your computer and use it in GitHub Desktop.
Save Fercell/a6e039d1e4babcefbada to your computer and use it in GitHub Desktop.
Whois and dig
require 'rainbow'
require 'whois'
require 'public_suffix'
require 'net/dns'
require 'rubygems'
require 'rainbow/ext/string'
#! /usr/bin/ruby
loop do
60.times { print "#" }
print "\nDomain: "
domain = $stdin.gets.chomp
domain.slice! "https://"
domain.slice! "http://"
new_domain = domain.split('/', 2)
domain = new_domain[0]
parsed_domain = PublicSuffix.parse("#{domain}")
domain = parsed_domain.domain
case domain
when "q"
exit
else
whois = Whois.whois(domain)
if whois.properties[:updated_on] == nil
false
else
if whois.updated_on >= Time.now - 86400
updated_on = "#{whois.updated_on}".color(:red)
else
updated_on = "#{whois.updated_on}".color(:green)
end
puts "Updated on: " + " " + updated_on
end
if whois.properties[:expires_on] == nil
false
else
if whois.expires_on < Time.now
expires_on = "#{whois.expires_on}".color(:red)
else
expires_on = "#{whois.expires_on}".color(:green)
end
puts "Expires on: " + " " + expires_on
end
if whois.properties[:registrar] == nil
true
else
if whois.registrar.name.downcase.include?("tucows") || whois.registrar.name.downcase.include?("publicdomainregistry")
puts "Registrar: " + " " + "#{whois.registrar.name}".color(:green)
else
puts "Registrar: " + " " + "#{whois.registrar.name}".color(:red)
end
end
if whois.status.to_s.include? "registered"
puts "Status: " + " " + "#{whois.status}".color(:green)
else
puts "Status: " + " " + "#{whois.status}".color(:red)
end
begin
ns = Net::DNS::Resolver.start(domain, Net::DNS::NS)
record_found = ns.answer.any? { |record|
record.is_a?(Net::DNS::RR::NS)
}
rescue Net::DNS::Resolver::NoResponseError
ns = []
end
puts 'Nameservers: '
if record_found
ns.each_nameserver {|n|
ip = %x(dig +short #{n}).chomp
if n.to_s.downcase.include?("hosting24.com") || n.to_s.downcase.include?("boxsecured.com")
if ip.include?("212.1.2") || ip.include?("185.28.2") || ip.include?("31.220.") || ip.include?("93.188.16")
puts " " + "#{n}".color(:green) + " [#{ip}]".color(:green)
else
puts " " + "#{n}".color(:red) + " [#{ip}]".color(:red)
end
else
if ip.include?("212.1.2") || ip.include?("185.28.2") || ip.include?("31.220.") || ip.include?("93.188.16")
puts " " + "#{n}".color(:green) + " [#{ip}]".color(:green)
else
puts " " + "#{n}".color(:red) + " [#{ip}]".color(:red)
end
end
}
else
puts "No records found!".color(:red)
end
begin
a = Net::DNS::Resolver.start(domain, Net::DNS::A)
record_found = a.answer.any? { |record|
record.is_a?(Net::DNS::RR::A)
}
rescue Net::DNS::Resolver::NoResponseError
a = []
end
puts 'A record: '
if record_found
a.each_address {|a| if a.to_s.include?("212.1.2") || a.to_s.include?("185.28.2") || a.to_s.include?("31.220.") || a.to_s.include?("93.188.16")
puts " " + "#{a}".color(:green)
else
puts " " + "#{a}".color(:red)
end
}
else
puts "No records found!"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment