class Gem::Resolv::Hosts
Gem::Resolv::Hosts
是一个使用系统 hosts 文件的域名解析器。
常量
- DefaultFileName
公共类方法
new(filename = DefaultFileName) 点击切换源代码
创建一个新的 Gem::Resolv::Hosts
,使用 filename
作为其数据源。
# File rubygems/vendor/resolv/lib/resolv.rb, line 192 def initialize(filename = DefaultFileName) @filename = filename @mutex = Thread::Mutex.new @initialized = nil end
公共实例方法
each_address(name, &proc) 点击切换源代码
遍历从 hosts 文件检索到的 name
的所有 IP 地址。
# File rubygems/vendor/resolv/lib/resolv.rb, line 239 def each_address(name, &proc) lazy_initialize @name2addr[name]&.each(&proc) end
each_name(address, &proc) 点击切换源代码
遍历从 hosts 文件检索到的 address
的所有主机名。
# File rubygems/vendor/resolv/lib/resolv.rb, line 264 def each_name(address, &proc) lazy_initialize @addr2name[address]&.each(&proc) end
getaddress(name) 点击切换源代码
从 hosts 文件获取 name
的 IP 地址。
# File rubygems/vendor/resolv/lib/resolv.rb, line 222 def getaddress(name) each_address(name) {|address| return address} raise ResolvError.new("#{@filename} has no name: #{name}") end
getaddresses(name) 点击切换源代码
从 hosts 文件获取 name
的所有 IP 地址。
# File rubygems/vendor/resolv/lib/resolv.rb, line 230 def getaddresses(name) ret = [] each_address(name) {|address| ret << address} return ret end
getname(address) 点击切换源代码
从 hosts 文件获取 address
的主机名。
# File rubygems/vendor/resolv/lib/resolv.rb, line 247 def getname(address) each_name(address) {|name| return name} raise ResolvError.new("#{@filename} has no address: #{address}") end
getnames(address) 点击切换源代码
从 hosts 文件获取 address
的所有主机名。
# File rubygems/vendor/resolv/lib/resolv.rb, line 255 def getnames(address) ret = [] each_name(address) {|name| ret << name} return ret end