I’m writing a script where it would be really good to be able to give
Resolv::DNS.new() an arbitrary list of DNS servers to use without having
to feed it a modified resolv.conf file. Is there a good way to do this?
I’d like to be able to do this:
r =
Resolv::DNS.new(nameservers=[‘127.0.0.1’,‘192.168.0.1’],search=[‘foo.com’])
a = r.getaddress($host)
Is there a good way to do this? The current Resolv::DNS seems to be
fixated on loading all it’s information from a resolv.conf or hosts file.
···
–
Daniel Hobe daniel@nightrunner.com
http://www.nightrunner.com
Daniel Hobe wrote:
I’m writing a script where it would be really good to be able to give
Resolv::DNS.new() an arbitrary list of DNS servers to use without having
to feed it a modified resolv.conf file. Is there a good way to do this?
I’d like to be able to do this:
r =
Resolv::DNS.new(nameservers=[‘127.0.0.1’,‘192.168.0.1’],search=[‘foo.com’])
a = r.getaddress($host)
Is there a good way to do this? The current Resolv::DNS seems to be
fixated on loading all it’s information from a resolv.conf or hosts file.
I solved my own question thusly:
#!/usr/bin/env ruby
require ‘resolv’
Thread.abort_on_exception = true
class Resolv::DNS2 < Resolv::DNS
def initialize(nameserver=[‘localhost’],search = nil,ndots=1)
@mutex = Mutex.new
@config = Config.new(nameserver,search,ndots)
@initialized = nil
end
class Config < Resolv::DNS::Config
def initialize(nameserver,search,ndots)
@mutex = Mutex.new
@nameserver = nameserver
@search = search
@ndots = ndots
@initialized = nil
end
def lazy_initialize
unless @search
hostname = Socket.gethostname
if /\./ =~ hostname
@search = [Resolv::DNS::Label.split($')]
else
@search = [[]]
end
end
end
end
end
d = Resolv::DNS2.new([‘216.220.40.243’,‘205.210.42.20’],
[[‘packetspike.net’],[‘nightrunner.com’]])
puts d.getaddress(‘www.packetspike.net’)
···
–
Daniel Hobe daniel@nightrunner.com
http://www.nightrunner.com