visitor (0 QPoints)
  • FR
  • EN
  • NL
  • DE
  • ES
315 experts, 1193 registered users, 1659 questions already answered
European Experts Exchange, the very best site for high-quality IT solutions

New Improved Search!

 


05/10/2011 1h30 : Steve Jobs is dead, the father of Apple ][ is gone, we are all orphaned.

Languages :: Csharp :: .Net :: retrieving Dns Server ip with .Net


By: VB guy Canada  Date: 19/07/2003 00:00:00  English  Points: 500 Status: Answered
Quality : Excellent
Thought someone could set me on the right path on how to retrieve
the DNS Server Ip with C#.


I'm looking for the dns server itself. seems to be lots of information on retrieving ips, domain names etc, but not the actual server. All suggestions are welcome.

I do see that the value is available in the registry at least on 2k, but would like to stay away from the registry if possible.

tia.

By: VGR Date: 20/07/2003 18:19:00 English  Type : Assist
well, if you shellExecute() a call to "nslookup 123.456.789.123", you'll see in the first returned row the IP@ and name of your DNS server, and then the results of the search. This is a possible quick&dirty solution when wanting to not read the Registry.
By: BorkBork Date: 20/07/2003 21:04:00 English  Type : Answer
Hi

I had this prob a while back. My solution was to use ipconfig.exe and parse its output. It's a bit of a hack and puts your prog at the mercy of non managed code. It has never given me a problem though. The code below will start an ipconfig process without a command window, redirect the output of the process to a string, which is then parsed for the IP addresses and placed in an array list. You'll need to modify the parsing if you have multiple network cards.

Hope this does the trick.


System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo("ipconfig", "/all");
psi.UseShellExecute = false;
psi.RedirectStandardOutput = true;
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo = psi;
p.Start();
p.WaitForExit();
System.Collections.ArrayList dnsIPs = new System.Collections.ArrayList();
string line = (p.StandardOutput.ReadLine());
while (line != null)
{
if (line.StartsWith(" DNS Servers . . . . . . . . . . . :"))
{
int i = line.IndexOf(":") + 2;
dnsIPs.Add(line.Substring(i, line.Length - i));
p.StandardOutput.ReadLine();
line = p.StandardOutput.ReadLine();
while(line.StartsWith(" "))
{
dnsIPs.Add(line.Substring(i, line.Length - i));
line = p.StandardOutput.ReadLine();
}
}
line = (p.StandardOutput.ReadLine());
}
By: VB guy Date: 21/07/2003 04:42:00 English  Type : Comment
Thanks for the responses, VGR and BorkBork.
Both of these are great and would work.. and I thank you both.

What I was hoping to find was a .Net solution that would not depend on
an OS for instance, ipconfig not available on 98.

I am willing to award the points, but was wondering if there is a pure .Net solution.

AlaskaSinbad


By: BorkBork Date: 22/07/2003 22:30:00 English  Type : Comment
The pure .Net solution would be to inspect the registry. Perhaps consider this control <A HREF="http://www.aspnetdns.com/">http://www.aspnetdns.com/</a> ? It may be overkill and probably justs encapsulates registry inspection anyway...

If TCP/IP is installed on windows 98 then ipconfig is also available. (Proof? -> <A HREF="http://www.helpdesk.umd.edu/os/windows_me/connectivity/ethernet/4311/">http://www.helpdesk.umd.edu/os/windows_me/connectivity/ethernet/4311/</a>)


By: VB guy Date: 30/07/2003 07:54:00 English  Type : Comment
Thanks guys, If I knew how to award more points I would, let me know if I know how to award more points.

thanks,

By: BorkBork Date: 31/07/2003 19:29:00 English  Type : Comment
No problem. 500 points was plenty. Thanks.

Do register to be able to answer

EContact
browser fav
page generated in 371.543880 milliseconds

Why Google AdSense ads ?

compteur
 Ranking-Hits PageRank for this page