Reputation: 34523
This SO post suggests checking domain availability through a combination of DNS lookups and WHOIS queries.
Unfortunately, it's not clear what the best way is to perform the DNS lookup in Ruby. The docs for the Dnsruby gem are sparse at best.
What's the most efficient way to use Dnsruby to see if a domain is taken already?
Thanks!
Upvotes: 0
Views: 1847
Reputation: 13077
This blog post titled Some examples of dnsruby in action has very detailed instructions for how to use dnsruby for common tasks.
Based on the steps mentioned there, I could verify the following behaviour in irb:
>> require 'dnsruby'
>> include DnsRuby
>> res = Resolver.new
=> #<Dnsruby::Resolver:0x00000100f4d2c8 @resolver_ruby=nil, @src_address=nil, @single_res_mutex=#<Mutex:0x00000100f4d278>, @configured=false, @do_caching=true, @config=Config - nameservers : 192.168.1.1, domain : empty, search : local, ndots : 1, @do_validation=false, @query_timeout=0, @retry_delay=5, @retry_times=1, @packet_timeout=5, @port=53, @udp_size=4096, @dnssec=true, @use_tcp=false, @no_tcp=false, @tsig=nil, @ignore_truncation=false, @src_port=[0], @recurse=true, @single_resolvers=[]>
>> res.query( 'www.google.com' )
=> ;; Answer received from 192.168.1.1 (123 bytes).... lengthy answer with A record info.
>> res.query( 'www.nonexistantsite.com' )
=> Throws an Dnsruby::NXDomain: Dnsruby::NXDomain exception.
Looks like wrapping this suitably in a ruby program is an easy way to perform DNS lookup with ruby.
Upvotes: 4