Class: Dnsruby::Resolv

### Home Classes Methods

### In Files

- lib/dnsruby/resolv.rb

### Parent

Object

### Methods

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

### Files

- DNSSEC
- EVENTMACHINE
- EXAMPLES

### Class/Module Index

Quicksearch

- Dnsruby
- Dnsruby::Algorithms
- Dnsruby::BitMapping
- Dnsruby::Bitmap
- Dnsruby::Classes
- Dnsruby::CodeMapper
- Dnsruby::Config
- Dnsruby::DNS
- Dnsruby::DecodeError
- Dnsruby::Dnssec
- Dnsruby::Dnssec::ValidationPolicy
- Dnsruby::EncodeError
- Dnsruby::ExtendedRCode
- Dnsruby::FormErr
- Dnsruby::Header
- Dnsruby::Hosts
- Dnsruby::IPv4
- Dnsruby::IPv6
- Dnsruby::Message
- Dnsruby::Message::SecurityLevel
- Dnsruby::MetaTypes
- Dnsruby::Modes
- Dnsruby::NXDomain
- Dnsruby::NXRRSet
- Dnsruby::Name
- Dnsruby::Name::Label
- Dnsruby::NotAuth
- Dnsruby::NotImp
- Dnsruby::NotZone
- Dnsruby::Nsec3HashAlgorithms
- Dnsruby::OpCode
- Dnsruby::OtherResolvError
- Dnsruby::QTypes
- Dnsruby::Question
- Dnsruby::RCode
- Dnsruby::RR
- Dnsruby::RR::ANY
- Dnsruby::RR::CERT
- Dnsruby::RR::CERT::CertificateTypes
- Dnsruby::RR::CNAME
- Dnsruby::RR::DHCID
- Dnsruby::RR::DLV
- Dnsruby::RR::DNAME
- Dnsruby::RR::DNSKEY
- Dnsruby::RR::DS
- Dnsruby::RR::DS::DigestTypes
- Dnsruby::RR::DomainName
- Dnsruby::RR::GPOS
- Dnsruby::RR::Generic
- Dnsruby::RR::HINFO
- Dnsruby::RR::HIP
- Dnsruby::RR::IN
- Dnsruby::RR::IN::A
- Dnsruby::RR::IN::AAAA
- Dnsruby::RR::IN::AFSDB
- Dnsruby::RR::IN::PX
- Dnsruby::RR::IN::SRV
- Dnsruby::RR::IN::WKS
- Dnsruby::RR::IPSECKEY
- Dnsruby::RR::ISDN
- Dnsruby::RR::KX
- Dnsruby::RR::LOC
- Dnsruby::RR::MB
- Dnsruby::RR::MG
- Dnsruby::RR::MINFO
- Dnsruby::RR::MR
- Dnsruby::RR::MX
- Dnsruby::RR::NAPTR
- Dnsruby::RR::NS
- Dnsruby::RR::NSAP
- Dnsruby::RR::NSEC
- Dnsruby::RR::NSEC3
- Dnsruby::RR::NSEC3PARAM
- Dnsruby::RR::NXT
- Dnsruby::RR::NXT::NxtTypes
- Dnsruby::RR::NXT::TypeBitmap
- Dnsruby::RR::OPT
- Dnsruby::RR::PTR
- Dnsruby::RR::RP
- Dnsruby::RR::RRSIG
- Dnsruby::RR::RT
- Dnsruby::RR::SOA
- Dnsruby::RR::SPF
- Dnsruby::RR::SSHFP
- Dnsruby::RR::SSHFP::Algorithms
- Dnsruby::RR::SSHFP::FpTypes
- Dnsruby::RR::TKEY
- Dnsruby::RR::TSIG
- Dnsruby::RR::TXT
- Dnsruby::RR::X25
- Dnsruby::RRSet
- Dnsruby::Recursor
- Dnsruby::Refused
- Dnsruby::Resolv
- Dnsruby::ResolvError
- Dnsruby::ResolvTimeout
- Dnsruby::Resolver
- Dnsruby::Resolver::EventType
- Dnsruby::Section
- Dnsruby::SelectThread
- Dnsruby::ServFail
- Dnsruby::SingleResolver
- Dnsruby::SocketEofResolvError
- Dnsruby::TheLog
- Dnsruby::TsigError
- Dnsruby::TsigNotSignedResponseError
- Dnsruby::Types
- Dnsruby::Update
- Dnsruby::VerifyError
- Dnsruby::YXDomain
- Dnsruby::YXRRSet
- Dnsruby::ZoneReader
- Dnsruby::ZoneReader::ParseException
- Dnsruby::ZoneSerialError
- Dnsruby::ZoneTransfer
- Dnsruby::ZoneTransfer::Delta
- Base32
- Object

No matching classes.

# Dnsruby::Resolv

NOTE! Beware, there is a Ruby library class named Resolv, and you may need to explicitly specify Dnsruby::Resolv to use the Dnsruby Resolv class, even if you have include'd Dnsruby.

### Constants

ADDRESS_REGEX

  Address RegExp to use for matching IP addresses

### Public Class Methods

each_address(name, &block) click to toggle source

Iterates over all IP addresses for `name`

    # File lib/dnsruby/resolv.rb, line 38
    def self.each_address(name, &block)
      instance.each_address(name, &block)
    end

each_name(address, &proc) click to toggle source

Iterates over all hostnames of `address`

    # File lib/dnsruby/resolv.rb, line 53
    def self.each_name(address, &proc)
      instance.each_name(address, &proc)
    end

getaddress(name) click to toggle source

Looks up the first IP address for `name`

    # File lib/dnsruby/resolv.rb, line 28
    def self.getaddress(name)
      instance.getaddress(name)
    end

getaddresses(name) click to toggle source

Looks up all IP addresses for `name`

    # File lib/dnsruby/resolv.rb, line 33
    def self.getaddresses(name)
      instance.getaddresses(name)
    end

getname(address) click to toggle source

Looks up the first hostname of `address`

    # File lib/dnsruby/resolv.rb, line 43
    def self.getname(address)
      instance.getname(address)
    end

getnames(address) click to toggle source

Looks up all hostnames of `address`

    # File lib/dnsruby/resolv.rb, line 48
    def self.getnames(address)
      instance.getnames(address)
    end

instance() click to toggle source

Some class methods require the use of an instance to compute their result. For this purpose we create a single instance that can be reused.

    # File lib/dnsruby/resolv.rb, line 20
    def self.instance
      @instance ||= self.new
    end

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

Creates a new Resolv using `resolvers`

    # File lib/dnsruby/resolv.rb, line 61
    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 lib/dnsruby/resolv.rb, line 87
    def each_address(name)
      getaddresses(name).each { |address| yield(address)}
    end

each_name(address) click to toggle source

Iterates over all hostnames of `address`

    # File lib/dnsruby/resolv.rb, line 112
    def each_name(address)
      getnames(address).each { |address| yield(address) }
    end

getaddress(name) click to toggle source

Looks up the first IP address for `name`

    # File lib/dnsruby/resolv.rb, line 66
    def getaddress(name)
      addresses = getaddresses(name)
      if addresses.empty?
        raise ResolvError.new("no address for #{name}")
      else
        addresses.first
      end
    end

getaddresses(name) click to toggle source

Looks up all IP addresses for `name`

    # File lib/dnsruby/resolv.rb, line 76
    def getaddresses(name)
      return [name] if ADDRESS_REGEX.match(name)
      @resolvers.each do |resolver|
        addresses = []
        resolver.each_address(name) { |address| addresses << address }
        return addresses unless addresses.empty?
      end
      []
    end

getname(address) click to toggle source

Looks up the first hostname of `address`

    # File lib/dnsruby/resolv.rb, line 92
    def getname(address)
      names = getnames(address)
      if names.empty?
        raise ResolvError.new("no name for #{address}")
      else
        names.first
      end
    end

getnames(address) click to toggle source

Looks up all hostnames of `address`

    # File lib/dnsruby/resolv.rb, line 102
    def getnames(address)
      @resolvers.each do |resolver|
        names = []
        resolver.each_name(address) { |name| names << name }
        return names unless names.empty?
      end
      []
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.