How to get DNS Server IP address?

  • Thread starter Thread starter Morgan Cheng
  • Start date Start date
M

Morgan Cheng

In windows, Dns.GetHostEntry invocation on a non-existent domain cost
time (about 25 seconds in my machine). So, I decide to implement my
own DNS resolution with UDP packet transfer.

One problem is that, how to get DNS server IP config for current
machine?
Thanks
 
This is one way (but only in .NET 2.0):

<code>
using System.Net.NetworkInformation
....
NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
foreach (NetworkInterface ni in nics)
{
if (ni.OperationalStatus == OperationalStatus.Up)
{
IPAddressCollection ips = ni.GetIPProperties().DnsAddresses;
foreach (System.Net.IPAddress ip in ips)
{
MessageBox.Show(ip.ToString());
}
}
}

</code>
 
This is one way (but only in .NET 2.0):

<code>
using System.Net.NetworkInformation
...
NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
foreach (NetworkInterface ni in nics)
{
if (ni.OperationalStatus == OperationalStatus.Up)
{
IPAddressCollection ips = ni.GetIPProperties().DnsAddresses;
foreach (System.Net.IPAddress ip in ips)
{
MessageBox.Show(ip.ToString());
}
}

}

</code>

Morgan Cheng said:
In windows, Dns.GetHostEntry invocation on a non-existent domain cost
time (about 25 seconds in my machine). So, I decide to implement my
own DNS resolution with UDP packet transfer.
One problem is that, how to get DNS server IP config for current
machine?
Thanks

It works . thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top