Skip to content

Instantly share code, notes, and snippets.

@mutle
Created February 13, 2009 14:28
Show Gist options
  • Save mutle/63925 to your computer and use it in GitHub Desktop.
Save mutle/63925 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'json'
require 'sinatra'
File.open('whois_proxy.pid', 'w') { |f| f.write(Process.pid) }
get '/whois/:tld/:domain' do
domain = (params['domain'] || '').gsub(/[^a-zA-Z0-9\-\_]/, '')
tld = (params['tld'] || '').gsub(/[^a-zA-Z0-9\-\_]/, '')
available = false
fqdn = "#{domain}.#{tld}"
if domain != '' and tld != ''
hostcheck = `host #{fqdn}`
if hostcheck.include?("does not exist") or hostcheck.include?("not found")
whois = `whois #{fqdn}`
available = true if whois.include?("No match") or whois.include?("not found in database") or whois.include?("NOT FOUND")
end
end
{
"#{params['domain']}.#{params['tld']}" => available
}.to_json
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment