[howto] get the nameserver name?

  • Thread starter Thread starter Wiktor Zychla
  • Start date Start date
W

Wiktor Zychla

In my code I have to query the local dns server for some data. however, I
have no idea how to get the name of the local DNS server.

could anyone point me the right direction?
thanks in advance,

Wiktor Zychla
 
Wiktor said:
In my code I have to query the local dns server for some data. however, I
have no idea how to get the name of the local DNS server.

could anyone point me the right direction?
thanks in advance,

Wiktor Zychla

Would System.Net.Dns class help you?
 
Would System.Net.Dns class help you?

If you can help to show me the proper method or property of this class, I
would be grateful. I make a heavy use of Dns class and didn't find any way
to get the nameserver name.
 
Wiktor said:
If you can help to show me the proper method or property of this class, I
would be grateful. I make a heavy use of Dns class and didn't find any way
to get the nameserver name.
Oh.. Sorry, I was thinking you wanted the services of Dns and not the
name. If you have enough privileges, you can check the
"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters"'s
"NameServer" string.
 
Wiktor Zychla said:
If you can help to show me the proper method or property of this class, I
would be grateful. I make a heavy use of Dns class and didn't find any way
to get the nameserver name.


You can use the System.Management methods:

class GetDNS
{
public static void Main()
{
ManagementObjectSearcher mos = new ManagementObjectSearcher(
"SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = 'TRUE'");
ManagementObjectCollection moc = mos.Get();
foreach(ManagementObject mo in moc)
{
Console.WriteLine("Network Card: {0}", mo["Description"]);
string[] hosts = (string[])mo["DNSServerSearchOrder"];
foreach(string host in hosts)
Console.WriteLine(" DNS host: {0}",host);
}
}
}

Hope this helps some.

Rich Blum - Author
"C# Network Programming" (Sybex)
http://www.sybex.com/sybexbooks.nsf/Booklist/4176
"Network Performance Open Source Toolkit" (Wiley)
http://www.wiley.com/WileyCDA/WileyTitle/productCd-0471433012.html
 
Back
Top