DNS servers

Published Wed, Oct 22 2003 8:33 | girishb
I saw this question about finding out the name of the "nameserver" on a given box. One way to do that would be to use the Registry classes and navigate to
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters
and look at the NameServer string value. The other way to do that would be through WMI. A VBScript example.
Set objs = GetObject("winmgmts:!root\cimv2").ExecQuery("select DNSHostName from Win32_NetworkAdapterConfiguration")
for each obj in objs
	if not isnull(obj.DnsHostName) then
		WScript.echo obj.DNSHostName (0) 
	end if
next 
The following accesses the WMI to find properties of the NetworkAdapter.
using System;
using System.Management;
            
class Sample_ManagementClass
{
	public static int Main(string[] args) {
		ManagementObjectSearcher mos = new ManagementObjectSearcher("select * from Win32_NetworkAdapterConfiguration where DatabasePath != null");
		foreach (ManagementObject mo in mos.Get()) {
			foreach (PropertyData pd in mo.Properties) {
				Console.WriteLine(pd.Name + "  = " + pd.Value);
			}
		}
		return 0;
	}
}

Comments

# TrackBack said on October 12, 2004 6:39 AM: