[Mono-dev] Unable to get the DNS server address

=?GB2312?B?s8LQ0Q==?= cxcxcxcx at gmail.com
Mon Nov 24 21:50:11 EST 2008


Hello. I want to get the default DNS server address currently used. In
Windows and .Net 2.0 , I can get it with the following code:

public static IPAddressCollection DiscoverDnsServerAddresses()
{
  NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
  foreach (NetworkInterface nic in nics)
  {
    if ( (nic.OperationalStatus == OperationalStatus.Up) && (nic.Speed > 0) &&
        (nic.NetworkInterfaceType != NetworkInterfaceType.Loopback)&&
        (nic.NetworkInterfaceType != NetworkInterfaceType.Tunnel))
    {
        return nic.GetIPProperties().DnsAddresses;
    }
  }
  return null;
}

But in mono, nic.GetIPProperties().DnsAddresses; returns a collection
with nothing in it.

I guess it's because that in Linux DNS server address is not
configured for each "Network Interface", but globally by
/etc/resolv.conf

However, I think it would be better if
nic.GetIPProperties().DnsAddresses; returns the collection of DNS
Servers currently used, even if all of them are same on Linux.

And I also wonder if there are ways to get the DNS Servers Address in
Linux with mono without parse /etc/resolv.conf mannualy?

ÒÔWikiģʽ´´½¨LinuxÖÐÎÄÎĵµ£¬»¶Ó­¼ÓÈë
http://www.linux-wiki.cn/


More information about the Mono-devel-list mailing list