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
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