类 Resolv
¶ ↑
Windows NT
¶ ↑
常量
- API
- 错误
- TCPIP_NT
公共类方法
get_hosts_path() 点击切换源代码
# File win32/lib/win32/resolv.rb, line 14 def self.get_hosts_path path = get_hosts_dir path = File.expand_path('hosts', path) File.exist?(path) ? path : nil end
get_resolv_info() 点击切换源代码
# File win32/lib/win32/resolv.rb, line 20 def self.get_resolv_info search, nameserver = get_info if search.empty? search = nil else search.delete("") search.uniq! end if nameserver.empty? nameserver = nil else nameserver.delete("") nameserver.delete("0.0.0.0") nameserver.uniq! end [ search, nameserver ] end
私有类方法
get_dns_server_list() 点击切换源代码
static VALUE get_dns_server_list(VALUE self) { FIXED_INFO *fixedinfo = NULL; ULONG buflen = 0; DWORD ret; VALUE buf, nameservers = Qnil; ret = GetNetworkParams(NULL, &buflen); if (ret != NO_ERROR && ret != ERROR_BUFFER_OVERFLOW) { w32error_raise(ret); } fixedinfo = ALLOCV(buf, buflen); ret = GetNetworkParams(fixedinfo, &buflen); if (ret == NO_ERROR) { const IP_ADDR_STRING *ipaddr = &fixedinfo->DnsServerList; nameservers = rb_ary_new(); do { const char *s = ipaddr->IpAddress.String; if (!*s) continue; if (strcmp(s, "0.0.0.0") == 0) continue; rb_ary_push(nameservers, rb_str_new_cstr(s)); } while ((ipaddr = ipaddr->Next) != NULL); } ALLOCV_END(buf); if (ret != NO_ERROR) w32error_raise(ret); return nameservers; }
get_hosts_dir() 点击切换源代码
# File win32/lib/win32/resolv.rb, line 69 def get_hosts_dir Registry::HKEY_LOCAL_MACHINE.open(TCPIP_NT) do |reg| reg.read_s_expand('DataBasePath') end end
get_info() 点击切换源代码
# File win32/lib/win32/resolv.rb, line 75 def get_info search = nil nameserver = get_dns_server_list Registry::HKEY_LOCAL_MACHINE.open(TCPIP_NT) do |reg| begin slist = reg.read_s('SearchList') search = slist.split(/,\s*/) unless slist.empty? rescue Registry::Error end if add_search = search.nil? search = [] begin nvdom = reg.read_s('NV Domain') unless nvdom.empty? @search = [ nvdom ] if reg.read_i('UseDomainNameDevolution') != 0 if /^\w+\./ =~ nvdom devo = $' end end end rescue Registry::Error end end reg.open('Interfaces') do |h| h.each_key do |iface, | h.open(iface) do |regif| next unless ns = %w[NameServer DhcpNameServer].find do |key| begin ns = regif.read_s(key) rescue Registry::Error else break ns.split(/[,\s]\s*/) unless ns.empty? end end next if (nameserver & ns).empty? if add_search begin [ 'Domain', 'DhcpDomain' ].each do |key| dom = regif.read_s(key) unless dom.empty? search.concat(dom.split(/,\s*/)) break end end rescue Registry::Error end end end end end search << devo if add_search and devo end [ search.uniq, nameserver.uniq ] end