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