Skip to content

Instantly share code, notes, and snippets.

Created August 7, 2010 01:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/512306 to your computer and use it in GitHub Desktop.
Save anonymous/512306 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
require "socket"
parts = Socket.gethostname.split(/\./);
host = parts.shift;
domain = parts.join('.');
soas = []
require 'resolv'
res = Resolv::DNS::new('/etc/resolv.conf')
p [ 'getting nameservers for ', domain ].join
nameservers = res.getresources( domain, Resolv::DNS::Resource::IN::NS)
nameservers.each {
|x|
soas.push(Resolv.getaddress(x.name.to_s) )
}
ares = Resolv::DNS::new( { :nameserver => soas, :search => [ domain ], :ndots => 1 } )
ares.each_resource(['loghost',domain].join('.'), Resolv::DNS::Resource::IN::ANY) do |r|
if r.kind_of?(Resolv::DNS::Resource::IN::MX) then
p [ r.preference.to_s, " ", r.exchange.to_s ].join
elsif r.kind_of?(Resolv::DNS::Resource::NS) then
p r.name.to_s
else
p r.name.to_s
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment