Windows NT
Constants
No documentation available
Class Methods
3.5
View on GitHub
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;
}
No documentation available
3.5
View on GitHub
# File tmp/rubies/ruby-3.5.0-preview1/ext/win32/lib/win32/resolv.rb, line 69
def get_hosts_dir
get_item_property(TCPIP_NT, 'DataBasePath', expand: true)
end
No documentation available
3.5
View on GitHub
# File tmp/rubies/ruby-3.5.0-preview1/ext/win32/lib/win32/resolv.rb, line 9
def self.get_hosts_path
path = get_hosts_dir
path = File.expand_path('hosts', path)
File.exist?(path) ? path : nil
end
No documentation available
.
3.5
View on GitHub
# File tmp/rubies/ruby-3.5.0-preview1/ext/win32/lib/win32/resolv.rb, line 73
def get_info
search = nil
nameserver = get_dns_server_list
slist = get_item_property(TCPIP_NT, 'SearchList')
search = slist.split(/,\s*/) unless slist.empty?
if add_search = search.nil?
search = []
nvdom = get_item_property(TCPIP_NT, 'NV Domain')
unless nvdom.empty?
@search = [ nvdom ]
udmnd = get_item_property(TCPIP_NT, 'UseDomainNameDevolution').to_i
if udmnd != 0
if /^\w+\./ =~ nvdom
devo = $'
end
end
end
end
ifs = if defined?(Win32::Registry)
Registry::HKEY_LOCAL_MACHINE.open(TCPIP_NT + '\Interfaces') do |reg|
reg.keys
rescue Registry::Error
[]
end
else
cmd = "Get-ChildItem 'HKLM:\\#{TCPIP_NT}\\Interfaces' | ForEach-Object { $_.PSChildName }"
output, _ = Open3.capture2('powershell', '-Command', cmd)
output.split(/\n+/)
end
ifs.each do |iface|
next unless ns = %w[NameServer DhcpNameServer].find do |key|
ns = get_item_property(TCPIP_NT + '\Interfaces' + "\\#{iface}", key)
break ns.split(/[,\s]\s*/) unless ns.empty?
end
next if (nameserver & ns).empty?
if add_search
[ 'Domain', 'DhcpDomain' ].each do |key|
dom = get_item_property(TCPIP_NT + '\Interfaces' + "\\#{iface}", key)
unless dom.empty?
search.concat(dom.split(/,\s*/))
break
end
end
end
end
search << devo if add_search and devo
[ search.uniq, nameserver.uniq ]
end
No documentation available
3.5
View on GitHub
# File tmp/rubies/ruby-3.5.0-preview1/ext/win32/lib/win32/resolv.rb, line 129
def get_item_property(path, name, expand: false)
if defined?(Win32::Registry)
Registry::HKEY_LOCAL_MACHINE.open(path) do |reg|
expand ? reg.read_s_expand(name) : reg.read_s(name)
rescue Registry::Error
""
end
else
cmd = "Get-ItemProperty -Path 'HKLM:\\#{path}' -Name '#{name}' -ErrorAction SilentlyContinue | Select-Object -ExpandProperty #{name}"
output, _ = Open3.capture2('powershell', '-Command', cmd)
output.strip
end
end
No documentation available
3.5
View on GitHub
# File tmp/rubies/ruby-3.5.0-preview1/ext/win32/lib/win32/resolv.rb, line 15
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
No documentation available