Class: Resolv (Ruby 2.7.3)
Description: Class : Resolv - Ruby 2.7.3

### Home Classes Methods

### In Files

- resolv.rb

### Parent

Object

### Namespace

- MODULE Resolv::LOC
- CLASS Resolv::DNS
- CLASS Resolv::Hosts
- CLASS Resolv::IPv4
- CLASS Resolv::IPv6
- CLASS Resolv::MDNS
- CLASS Resolv::ResolvError
- CLASS Resolv::ResolvTimeout

### Methods

- ::each_address
- ::each_name
- ::getaddress
- ::getaddresses
- ::getname
- ::getnames
- ::new
- #each_address
- #each_name
- #getaddress
- #getaddresses
- #getname
- #getnames

### Class/Module Index

Quicksearch

- Resolv
- Resolv::DNS
- Resolv::DNS::Config
- Resolv::DNS::Config::NXDomain
- Resolv::DNS::Config::OtherResolvError
- Resolv::DNS::DecodeError
- Resolv::DNS::EncodeError
- Resolv::DNS::Name
- Resolv::DNS::Query
- Resolv::DNS::Requester
- Resolv::DNS::Requester::RequestError
- Resolv::DNS::Resource
- Resolv::DNS::Resource::ANY
- Resolv::DNS::Resource::CNAME
- Resolv::DNS::Resource::DomainName
- Resolv::DNS::Resource::Generic
- Resolv::DNS::Resource::HINFO
- Resolv::DNS::Resource::IN
- Resolv::DNS::Resource::IN::A
- Resolv::DNS::Resource::IN::AAAA
- Resolv::DNS::Resource::IN::SRV
- Resolv::DNS::Resource::IN::WKS
- Resolv::DNS::Resource::LOC
- Resolv::DNS::Resource::MINFO
- Resolv::DNS::Resource::MX
- Resolv::DNS::Resource::NS
- Resolv::DNS::Resource::PTR
- Resolv::DNS::Resource::SOA
- Resolv::DNS::Resource::TXT
- Resolv::Hosts
- Resolv::IPv4
- Resolv::IPv6
- Resolv::LOC
- Resolv::LOC::Alt
- Resolv::LOC::Coord
- Resolv::LOC::Size
- Resolv::MDNS
- Resolv::ResolvError
- Resolv::ResolvTimeout

No matching classes.

# Resolv

`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(&:address)
      ress = dns.getresources "ruby-lang.org", Resolv::DNS::Resource::IN::MX
      p ress.map { |r| [r.exchange.to_s, r.preference] }
    end

## Bugs¶ ↑

- NIS is not supported.

- /etc/nsswitch.conf is not supported.

### Constants

AddressRegex

  Address Regexp to use for matching IP addresses.

DefaultResolver

  Default resolver to use for `Resolv` class methods.

### Public Class Methods

each_address(name, &block) click to toggle source

Iterates over all IP addresses for `name`.

                   # File resolv.rb, line 57
    def self.each_address(name, &block)
      DefaultResolver.each_address(name, &block)
    end

each_name(address, &proc) click to toggle source

Iterates over all hostnames for `address`.

                   # File resolv.rb, line 78
    def self.each_name(address, &proc)
      DefaultResolver.each_name(address, &proc)
    end

getaddress(name) click to toggle source

Looks up the first IP address for `name`.

                   # File resolv.rb, line 43
    def self.getaddress(name)
      DefaultResolver.getaddress(name)
    end

getaddresses(name) click to toggle source

Looks up all IP address for `name`.

                   # File resolv.rb, line 50
    def self.getaddresses(name)
      DefaultResolver.getaddresses(name)
    end

getname(address) click to toggle source

Looks up the hostname of `address`.

                   # File resolv.rb, line 64
    def self.getname(address)
      DefaultResolver.getname(address)
    end

getnames(address) click to toggle source

Looks up all hostnames for `address`.

                   # File resolv.rb, line 71
    def self.getnames(address)
      DefaultResolver.getnames(address)
    end

new(resolvers=[Hosts.new, DNS.new]) click to toggle source

Creates a new `Resolv` using `resolvers`.

                   # File resolv.rb, line 85
    def initialize(resolvers=[Hosts.new, DNS.new])
      @resolvers = resolvers
    end

### Public Instance Methods

each_address(name) click to toggle source

Iterates over all IP addresses for `name`.

                   # File resolv.rb, line 109
    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

each_name(address) click to toggle source

Iterates over all hostnames for `address`.

                   # File resolv.rb, line 144
    def each_name(address)
      yielded = false
      @resolvers.each {|r|
        r.each_name(address) {|name|
          yield name.to_s
          yielded = true
        }
        return if yielded
      }
    end

getaddress(name) click to toggle source

Looks up the first IP address for `name`.

                   # File resolv.rb, line 92
    def getaddress(name)
      each_address(name) {|address| return address}
      raise ResolvError.new("no address for #{name}")
    end

getaddresses(name) click to toggle source

Looks up all IP address for `name`.

                   # File resolv.rb, line 100
    def getaddresses(name)
      ret = []
      each_address(name) {|address| ret << address}
      return ret
    end

getname(address) click to toggle source

Looks up the hostname of `address`.

                   # File resolv.rb, line 127
    def getname(address)
      each_name(address) {|name| return name}
      raise ResolvError.new("no name for #{address}")
    end

getnames(address) click to toggle source

Looks up all hostnames for `address`.

                   # File resolv.rb, line 135
    def getnames(address)
      ret = []
      each_name(address) {|name| ret << name}
      return ret
    end