Support Forums
[C#] DNS to IP [Beginner] - Printable Version

+- Support Forums (https://www.supportforums.net)
+-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87)
+--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18)
+---- Forum: Visual Basic and the .NET Framework (https://www.supportforums.net/forumdisplay.php?fid=19)
+---- Thread: [C#] DNS to IP [Beginner] (/showthread.php?tid=11676)



[C#] DNS to IP [Beginner] - Mike - 08-31-2010

This one is very simple. Everybody should now how to do this.

Imports:
Code:
using System.Net;

Code:
Code:
static string DNStoIP(string DNS)
        {
            try
            {
                IPHostEntry DNSHosts = Dns.GetHostEntry(DNS);
                IPAddress[] DNSIPs = DNSHosts.AddressList;
                return Convert.ToString(DNSIPs[0]);
            }
            catch (Exception ex)
            {
                throw ex;
            }

Usage:
Code:
Console.WriteLine(DNStoIP("google.com"));



RE: [C#] DNS to IP [Beginner] - xHtmlPhP - 09-02-2010

This is new to me; I've never used Dns.GetHostEntry before since you can do the same action using ping/reply.

Well thanks for this thread and you certainly taught me something new ;)


RE: [C#] DNS to IP [Beginner] - Sιℓνєя - 09-03-2010

Thanks for this (:


RE: [C#] DNS to IP [Beginner] - Mike - 09-03-2010

You're welcome everybody!


RE: [C#] DNS to IP [Beginner] - flAmingw0rm - 09-05-2010

Thanks, it works perfectly.


RE: [C#] DNS to IP [Beginner] - pers2981 - 09-09-2010

wait cant you just goto cmd and do tracert (dns) then it give you the iP?