Support Forums

Full Version: [C#] DNS to IP [Beginner]
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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"));
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 ;)
Thanks for this (:
You're welcome everybody!
Thanks, it works perfectly.
wait cant you just goto cmd and do tracert (dns) then it give you the iP?