Skip to content

Instantly share code, notes, and snippets.

@tarolandia
Created December 26, 2011 15:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tarolandia/1521384 to your computer and use it in GitHub Desktop.
Save tarolandia/1521384 to your computer and use it in GitHub Desktop.
whois server
require 'rubygems'
require 'sinatra'
require 'whois'
require 'json'
get '/whois/:domain' do |domain|
c = Whois::Client.new
r = c.query(domain)
puts r
r
end
require 'rubygems'
require 'sinatra'
require 'whois'
require 'json'
get '/whois/:domain' do |domain|
c = Whois::Client.new
r = c.query(domain)
t = r.registrar
if t.name.nil?
if r.to_s.downcase =~ /godaddy.com,\sinc/
response = { :domain => domain, :registrar => "godaddy" }
else
response = {}
end
else
response = { :domain => domain, :registrar => t.name }
end
response.to_json
#r.to_s.downcase
end
require 'rubygems'
require 'sinatra'
require 'whois'
require 'json'
get '/whois/:domain' do |domain|
dom_parts = domain.split(".")
status = false
until dom_parts.size < 2 or status
begin
c = Whois::Client.new
r = c.query(dom_parts.join("."))
status = true
rescue Whois::Error => e
dom_parts.shift
end
end
response = Hash.new
response[:registrar] = ""
if status
t = r.registrar
if t.name.nil?
if r.to_s.downcase =~ /godaddy.com,\sinc/
response[:registrar] = "GoDaddy.com, Inc."
end
else
response[:registrar] = t.name
end
end
response.to_json
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment