Class: Dnsruby::DNS

### Home Classes Methods

### In Files

- lib/dnsruby/DNS.rb

### Parent

Object

### Methods

- ::new
- ::open
- #close
- #each_address
- #each_name
- #each_resource
- #getaddress
- #getaddresses
- #getname
- #getnames
- #getresource
- #getresources
- #to_s

### 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::DNS

## Dnsruby::DNS class

Resolv::DNS performs DNS queries.

### class methods

- Dnsruby::DNS.new(config_info=nil)

      ((|config_info|)) should be nil, a string or a hash.
      If nil is given, /etc/resolv.conf and platform specific information is used.
      If a string is given, it should be a filename which format is same as /etc/resolv.conf.
      If a hash is given, it may contains information for nameserver, search and ndots as follows.

        Dnsruby::DNS.new({:nameserver=>["210.251.121.21"], :search=>["ruby-lang.org"], :ndots=>1})

- Dnsruby::DNS.open(config_info=nil)

- Dnsruby::Resolv::DNS.open(config_info=nil) {|dns| ...}

### methods

- Dnsruby::DNS#close

- Dnsruby::DNS#getaddress(name)

- Dnsruby::DNS#getaddresses(name)

- Dnsruby::DNS#each_address(name) {|address| ...}

      address lookup methods.

      ((|name|)) must be an instance of Dnsruby::Name or String.  Resultant
      address is represented as an instance of Dnsruby::IPv4 or Dnsruby::IPv6.

- Dnsruby::DNS#getname(address)

- Dnsruby::DNS#getnames(address)

- Dnsruby::DNS#each_name(address) {|name| ...}

      These methods lookup hostnames .

      ((|address|)) must be an instance of Dnsruby::IPv4, Dnsruby::IPv6 or String.
      Resultant name is represented as an instance of Dnsruby::Name.

- Dnsruby::DNS#getresource(name, type, class)

- Dnsruby::DNS#getresources(name, type, class)

- Dnsruby::DNS#each_resource(name, type, class) {|resource| ...}

      These methods lookup DNS resources of ((|name|)).
      ((|name|)) must be a instance of Dnsruby::Name or String.

      ((|type|)) must be a member of Dnsruby::Types
      ((|class|)) must be a member of Dnsruby::Classes

      Resultant resource is represented as an instance of (a subclass of)
      Dnsruby::RR.
      (Dnsruby::RR::IN::A, etc.)

The searchlist and other Config info is applied to the domain name if appropriate. All the nameservers are tried (if there is no timely answer from the first).

This class uses Resolver to perform the queries.

Information taken from the following places :

- STD0013

- RFC 1035, etc.

- ftp.isi.edu/in-notes/iana/assignments/dns-parameters

- etc.

### Attributes

config[R]
do_caching[RW]

### Public Class Methods

new(config_info=nil) click to toggle source

Creates a new DNS resolver

`config_info` can be:

- nil | Uses platform default (e.g. /etc/resolv.conf)

- String | Path to a file using /etc/resolv.conf's format

- Hash | Must contain :nameserver, :search and :ndots keys

      example :

       Dnsruby::DNS.new({:nameserver => ['210.251.121.21'],
                         :search => ['ruby-lang.org'],
                         :ndots => 1})

    # File lib/dnsruby/DNS.rb, line 118
        def initialize(config_info=nil)
          @do_caching = true
          @config = Config.new()
          @config.set_config_info(config_info)
          @resolver = Resolver.new(@config)
    #      if (@resolver.single_resolvers.length == 0)
    #        raise ArgumentError.new("Must pass at least one valid resolver address")
    #      end
        end

open(*args) click to toggle source

Creates a new DNS resolver. See Resolv::DNS.new for argument details.

Yields the created DNS resolver to the block, if given, otherwise returns it.

    # File lib/dnsruby/DNS.rb, line 86
    def self.open(*args)
      dns = new(*args)
      return dns unless block_given?
      begin
        yield dns
      ensure
        dns.close
      end
    end

### Public Instance Methods

close() click to toggle source

Closes the resolver

    # File lib/dnsruby/DNS.rb, line 97
    def close
      @resolver.close
    end

each_address(name) click to toggle source

Iterates over all IP addresses of `name` retrieved from the DNS resolver

`name` can be a Dnsruby::Name or a String. Retrieved address will be a Dnsruby::IPv4 or a Dnsruby::IPv6

    # File lib/dnsruby/DNS.rb, line 153
    def each_address(name)
      each_resource(name) {|resource| yield resource.address}
    end

each_name(address) click to toggle source

Iterates over all hostnames for `address` retrieved from the DNS resolver

`address` must be a Dnsruby::IPv4, Dnsruby::IPv6 or a String. Retrieved name will be a Dnsruby::Name.

    # File lib/dnsruby/DNS.rb, line 180
    def each_name(address)
      case address
      when Name
        ptr = address
      when  IPv4, IPv6
        ptr = address.to_name
      when IPv4::Regex
        ptr = IPv4.create(address).to_name
      when IPv6::Regex
        ptr = IPv6.create(address).to_name
      else
        raise ResolvError.new("cannot interpret as address: #{address}")
      end
      each_resource(ptr, Types.PTR, Classes.IN) {|resource| yield resource.domainname}
    end

each_resource(name, type=Types.A, klass=Classes.IN, &proc) click to toggle source

Iterates over all `type`, `klass` resources for `name`

`type` defaults to Dnsruby::Types.A `klass` defaults to Dnsruby::Classes.IN

Yielded resource is represented as a Dnsruby::RR instance, e.g. Dnsruby::RR::IN::A

    # File lib/dnsruby/DNS.rb, line 228
    def each_resource(name, type=Types.A, klass=Classes.IN, &proc)
      type = Types.new(type)
      klass = Classes.new(klass)
      reply, reply_name = send_query(name, type, klass)
      case reply.rcode.code
      when RCode::NOERROR
        extract_resources(reply, reply_name, type, klass, &proc)
        return
        #       when RCode::NXDomain
        #         Dnsruby.log.debug("RCode::NXDomain returned - raising error")
        #         raise Config::NXDomain.new(reply_name.to_s)
      else
        Dnsruby.log.error{"Unexpected rcode : #{reply.rcode.string}"}
        raise Config::OtherResolvError.new(reply_name.to_s)
      end
    end

getaddress(name) click to toggle source

Gets the first IP address of `name` from the DNS resolver

`name` can be a Dnsruby::Name or a String. Retrieved address will be a Dnsruby::IPv4 or a Dnsruby::IPv6

    # File lib/dnsruby/DNS.rb, line 134
    def getaddress(name)
      each_address(name) {|address| return address}
      raise ResolvError.new("DNS result has no information for #{name}")
    end

getaddresses(name) click to toggle source

Gets all IP addresses of `name` from the DNS resolver

`name` can be a Dnsruby::Name or a String. Retrieved address will be a Dnsruby::IPv4 or a Dnsruby::IPv6

    # File lib/dnsruby/DNS.rb, line 143
    def getaddresses(name)
      ret = []
      each_address(name) {|address| ret << address}
      return ret
    end

getname(address) click to toggle source

Gets the first hostname for `address` from the DNS resolver

`address` must be a Dnsruby::IPv4, Dnsruby::IPv6 or a String. Retrieved name will be a Dnsruby::Name.

    # File lib/dnsruby/DNS.rb, line 161
    def getname(address)
      each_name(address) {|name| return name}
      raise ResolvError.new("DNS result has no information for #{address}")
    end

getnames(address) click to toggle source

Gets all hostnames for `address` from the DNS resolver

`address` must be a Dnsruby::IPv4, Dnsruby::IPv6 or a String. Retrieved name will be a Dnsruby::Name.

    # File lib/dnsruby/DNS.rb, line 170
    def getnames(address)
      ret = []
      each_name(address) {|name| ret << name}
      return ret
    end

getresource(name, type=Types.A, klass=Classes.IN) click to toggle source

Look up the first `type`, `klass` resource for `name`

`type` defaults to Dnsruby::Types.A `klass` defaults to Dnsruby::Classes.IN

Returned resource is represented as a Dnsruby::RR instance, e.g. Dnsruby::RR::IN::A

    # File lib/dnsruby/DNS.rb, line 203
    def getresource(name, type=Types.A, klass=Classes.IN)
      each_resource(name, type, klass) {|resource| return resource}
      raise ResolvError.new("DNS result has no information for #{name}")
    end

getresources(name, type=Types.A, klass=Classes.IN) click to toggle source

Look up all `type`, `klass` resources for `name`

`type` defaults to Dnsruby::Types.A `klass` defaults to Dnsruby::Classes.IN

Returned resource is represented as a Dnsruby::RR instance, e.g. Dnsruby::RR::IN::A

    # File lib/dnsruby/DNS.rb, line 215
    def getresources(name, type=Types.A, klass=Classes.IN)
      ret = []
      each_resource(name, type, klass) {|resource| ret << resource}
      return ret
    end

to_s() click to toggle source

    # File lib/dnsruby/DNS.rb, line 102
    def to_s
      return "DNS : " + @config.to_s
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.