Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save streetcarmonkey/c313024cb4cbf706a217 to your computer and use it in GitHub Desktop.
Save streetcarmonkey/c313024cb4cbf706a217 to your computer and use it in GitHub Desktop.
Ruby script using whois gem to check whois for emails and domain expiry details
require 'whois'
def check_whois_for_emails_and_domain_expiry(domain = 'microsoft.com')
puts "Getting whois info for #{domain}"
emails = Hash.new
registration_details = Hash.new
r = Whois.whois(domain)
if r.technical_contact.nil? then emails[:technical_contact] = '' else emails[:technical_contact] = r.technical_contact['email'].downcase end
if r.registrant_contact.nil? then emails[:registrant_contact] = '' else emails[:registrant_contact] = r.registrant_contact['email'].downcase end
if r.admin_contact.nil? then emails[:admin_contact] = '' else emails[:admin_contact] = r.admin_contact['email'].downcase end
if r.created_on.nil? then registration_details[:created_on] = '' else registration_details[:created_on] = r.created_on end
if r.updated_on.nil? then registration_details[:updated_on] = '' else registration_details[:updated_on] = r.updated_on end
if r.expires_on.nil? then registration_details[:expires_on] = '' else registration_details[:expires_on] = r.expires_on end
return emails, registration_details
end
emails, registration_details = check_whois_for_emails_and_domain_expiry #apple.com
emails.each do | email | puts "#{email.first.to_s}: #{email.last}" end
registration_details.each do | detail | puts "#{detail.first.to_s}: #{detail.last}" end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment