[Mono-list] How to get the DNS server address?

Petit Eric surfzoid at gmail.com
Fri Nov 28 08:01:42 EST 2008


2008/11/28 chenxing <cxcxcxcx at gmail.com>:
>
> 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:
using System;

using System.IO;

using System.Net;

using System.Net.Sockets;

Dns.GetHostEntry(Varglobal.ServerAdress).AddressList[0];    ?
>
> 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
>
> I wonder if there are ways to get the DNS Servers Address in Linux with mono
> without parse /etc/resolv.conf mannualy?
> --
> View this message in context: http://www.nabble.com/How-to-get-the-DNS-server-address--tp20733912p20733912.html
> Sent from the Mono - General mailing list archive at Nabble.com.
>
> _______________________________________________
> Mono-list maillist  -  Mono-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list
>



-- 

Cordially.

Small Eric Quotations of the days:
---------------------------------------------------------------------------
If one day one reproaches you that your work is not a work of
professional, say you that:
Amateurs built the arch of Noah, and professionals the Titanic.
---------------------------------------------------------------------------

Few people are done for independence, it is the privilege of the powerful ones.
---------------------------------------------------------------------------

No key was wounded during the drafting of this message.


More information about the Mono-list mailing list