I need to get the txt field from the DNS record. Is there any ruby api to do something like this?
nslookup -q=txt xxxx.com
Thanks
I need to get the txt field from the DNS record. Is there any ruby api to do something like this?
nslookup -q=txt xxxx.com
Thanks
Try the Net::DNS gem. Scroll down on that page for installation and usage instructions.
Try installing the dnsruby gem.
The code is actively maintained, and used in some significant production systems.
require 'rubygems'
require 'dnsruby'
include Dnsruby
# Use the system configured nameservers to run a query
res = Dnsruby::Resolver.new
ret = res.query("google.com", Types.TXT)
print ret.answer
(Code tested on MacOS X - prints the Google SPF record)
See also @Alex's answer which is more idiomatic Ruby - Alex is the author of dnsruby
.
require 'dnsruby'
Dnsruby::DNS.open {|dns|
dns.each_resource("google.com", "TXT") {|rr| print rr}
# or
print dns.getresource("google.com", "TXT")}
}