我在 Ruby 文档中找不到任何关于如何设置超时以使用 Resolv 类(来自 Ruby 标准库)的类方法 getaddress 来检索域的 IP 的任何内容。
问问题
1065 次
2 回答
2
查看 Resolv的源代码,在第 353 行,我可以看到 DNS 类中定义了一个名为 timeouts 的方法。您应该能够使用它来更改超时。
# Sets the resolver timeouts. This may be a single positive number
# or an array of positive numbers representing timeouts in seconds.
# If an array is specified, a DNS request will retry and wait for
# each successive interval in the array until a successful response
# is received. Specifying +nil+ reverts to the default timeouts:
# [ 5, second = 5 * 2 / nameserver_count, 2 * second, 4 * second ]
#
# Example:
#
# dns.timeouts = 3
#
def timeouts=(values)
@config.timeouts = values
end
于 2016-08-13T22:19:51.590 回答
2
超时选项可以这样使用:
Resolv::DNS.open do |dns|
dns.timeouts = 1
host = dns.getname "172.28.0.1"
puts "hostname: #{host}"
end
于 2020-11-23T17:18:29.493 回答