Object
Resolv is a thread-aware DNS resolver library written in Ruby. Resolv can handle multiple DNS requests concurrently without blocking the entire ruby interpreter.
See also resolv-replace.rb to replace the libc resolver with Resolv.
Resolv can look up various DNS resources using the DNS module directly.
Examples:
p Resolv.getaddress "www.ruby-lang.org" p Resolv.getname "210.251.121.214" Resolv::DNS.open do |dns| ress = dns.getresources "www.ruby-lang.org", Resolv::DNS::Resource::IN::A p ress.map { |r| r.address } ress = dns.getresources "ruby-lang.org", Resolv::DNS::Resource::IN::MX p ress.map { |r| [r.exchange.to_s, r.preference] } end
NIS is not supported.
/etc/nsswitch.conf is not supported.
Address Regexp to use for matching IP addresses.
Default resolver to use for Resolv class methods.
Iterates over all IP addresses for name
.
# File resolv.rb, line 56 def self.each_address(name, &block) DefaultResolver.each_address(name, &block) end
Iterates over all hostnames for address
.
# File resolv.rb, line 77 def self.each_name(address, &proc) DefaultResolver.each_name(address, &proc) end
Looks up the first IP address for name
.
# File resolv.rb, line 42 def self.getaddress(name) DefaultResolver.getaddress(name) end
Looks up all IP address for name
.
# File resolv.rb, line 49 def self.getaddresses(name) DefaultResolver.getaddresses(name) end
Looks up the hostname of address
.
# File resolv.rb, line 63 def self.getname(address) DefaultResolver.getname(address) end
Looks up all hostnames for address
.
# File resolv.rb, line 70 def self.getnames(address) DefaultResolver.getnames(address) end
Creates a new Resolv using
resolvers
.
# File resolv.rb, line 84 def initialize(resolvers=[Hosts.new, DNS.new]) @resolvers = resolvers end
Iterates over all IP addresses for name
.
# File resolv.rb, line 108 def each_address(name) if AddressRegex =~ name yield name return end yielded = false @resolvers.each {|r| r.each_address(name) {|address| yield address.to_s yielded = true } return if yielded } end
Iterates over all hostnames for address
.
# File resolv.rb, line 143 def each_name(address) yielded = false @resolvers.each {|r| r.each_name(address) {|name| yield name.to_s yielded = true } return if yielded } end
Looks up the first IP address for name
.
# File resolv.rb, line 91 def getaddress(name) each_address(name) {|address| return address} raise ResolvError.new("no address for #{name}") end
Looks up all IP address for name
.
# File resolv.rb, line 99 def getaddresses(name) ret = [] each_address(name) {|address| ret << address} return ret end
Commenting is here to help enhance the documentation. For example, sample code, or clarification of the documentation.
If you are posting code samples in your comments, please wrap them in "<pre><code class="ruby" > ... </code></pre>" markup in order to get syntax highlighting.
If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.
If you wish to post a correction of the docs, please do so, but also file a bug report so that it can be corrected for the next release. Thank you.