Ruby 2.4

Resolv::DNS

Resolv::DNS类

Parent:Object

Resolv :: DNS是一个DNS存根解析器。

从以下地点获取信息:

  • STD0013

  • RFC 1035

  • etc.

常量

端口

默认DNS端口

UDPSize

默认DNS UDP数据包大小

公共类方法

new(config_info=nil) Show source

创建一个新的DNS解析器。

config_info 可以为:

Uses /etc/resolv.conf.

字符串

使用/etc/resolv.conf格式的文件路径。

Hash

必须包含:nameserver,:search和:ndots键。

:nameserver_port可用于指定名称服务器地址的端口号。

nameserver的值应该是地址字符串或地址字符串数组。

  • :nameserver => '8.8.8.8'

  • :nameserver => '8.8.8.8', '8.8.4.4'

nameserver_port的值应该是一对名称服务器地址和端口号的数组。

:nameserver_port => ['8.8.8.8', 53, '8.8.4.4', 53]Example:Resolv::DNS.new(:nameserver => ['210.251.121.21'], :search => ['ruby-lang.org'], :ndots => 1)# File lib/resolv.rb, line 333 def initialize(config_info=nil) @mutex = Thread::Mutex.new @config = Config.new(config_info) @initialized = nil end open(*args) { |dns| ... }

  • Resolv::DNS::Resource::IN::A

  • Resolv::DNS::Resource::IN::AAAA

  • Resolv::DNS::Resource::IN::ANY

  • Resolv::DNS::Resource::IN::CNAME

  • Resolv::DNS::Resource::IN::HINFO

  • Resolv::DNS::Resource::IN::MINFO

  • Resolv::DNS::Resource::IN::MX

  • Resolv::DNS::Resource::IN::NS

  • Resolv::DNS::Resource::IN::PTR

  • Resolv::DNS::Resource::IN::SOA

  • Resolv::DNS::Resource::IN::TXT

  • Resolv::DNS::Resource::IN::WKS

返回的资源表示为Resolv :: DNS :: Resource实例,即Resolv :: DNS :: Resource :: IN :: A。

# File lib/resolv.rb, line 489 def getresource(name, typeclass) each_resource(name, typeclass) {|resource| return resource} raise ResolvError.new("DNS result has no information for #{name}") end

getresources(name, typeclass) Show source

查找所有typeclassDNS资源name。有关参数详情,请参阅getresource。

# File lib/resolv.rb, line 498 def getresources(name, typeclass) ret = [] each_resource(name, typeclass) {|resource| ret << resource} return ret end

timeouts=(values) Show source

设置解析器超时。 这可能是一个单一的正数或表示超时秒数的正数的数组。 如果指定了数组,则DNS请求将重试并等待数组中的每个连续时间间隔,直到收到成功的响应。 指定nil将恢复为默认超时:

5, second = 5 * 2 / nameserver_count, 2 * second, 4 * second

例:

dns.timeouts = 3

# File lib/resolv.rb, line 350 def timeouts=(values) @config.timeouts = values end