Resolv::Hosts
class Resolv::Hosts
父类:Object
Resolv :: Hosts是使用系统主机文件的主机名解析程序。
常量
DefaultFileName
公共类方法
新(文件名= DefaultFileName)显示源
创建一个新的Resolv :: Hosts,filename
用于其数据源。
# File lib/resolv.rb, line 180
def initialize(filename = DefaultFileName)
@filename = filename
@mutex = Thread::Mutex.new
@initialized = nil
end
公共实例方法
each_address(名称,&proc)显示源文件
遍历name
从主机文件中检索的所有IP地址。
# File lib/resolv.rb, line 237
def each_address(name, &proc)
lazy_initialize
if @name2addr.include?(name)
@name2addr[name].each(&proc)
end
end
each_name(地址,&proc)显示源
遍历address
从主机文件中检索的所有主机名。
# File lib/resolv.rb, line 264
def each_name(address, &proc)
lazy_initialize
@addr2name[address]&.each(&proc)
end
getaddress(名称)显示源
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
从主机文件获取所有IP地址。
# File lib/resolv.rb, line 228
def getaddresses(name)
ret = []
each_address(name) {|address| ret << address}
return ret
end
getname(地址)显示源
address
从主机文件获取主机名。
# File 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
从主机文件获取所有主机名。
# File lib/resolv.rb, line 255
def getnames(address)
ret = []
each_name(address) {|name| ret << name}
return ret
end