这是我的测试代码:
require 'resolv'
puts `dig @172.17.0.40 -x 203.208.60.1 +short`
puts `dig @172.17.0.40 -x 192.168.12.100 +short`
resolver = Resolv::DNS.new(
:nameserver => ['172.17.0.40'],
:search => ['example.com'],
:ndots => 1
)
puts resolver.getname('203.208.60.1')
puts resolver.getname('192.168.12.100')
运行上面的脚本会导致:
crawl-203-208-60-1.googlebot.com.
asdf.example.com.
crawl-203-208-60-1.googlebot.com
/home/jskarpet/.rvm/rubies/ruby-2.1.3/lib/ruby/2.1.0/resolv.rb:431:in `getname': DNS result has no information for 192.168.12.100 (Resolv::ResolvError)
from ruby.rb:14:in `<main>'
为什么使用 Resolv 查找失败,而不是挖掘(以及如何修复?)