• How to do DNS Lookup in C#

    Posted on May 8, 2013 by in Dotnet Tips & Tricks, Tips & Tricks

    Namespaces:

    using System;
    using System.Net;
    using System.Net.NetworkInformation;

    Code:

    public static void DNSLookup(string hostNameOrAddress)
    {    
        IPHostEntry hostEntry = Dns.GetHostEntry(hostNameOrAddress);
    
        IPAddress[] ips = hostEntry.AddressList;
    
        foreach (IPAddress address in ips)
        {
            Console.WriteLine(address.ToString());
        }            
    }

    Usage:

    NetworkHelper.DNSLookup("www.google.com");

    DNS Lookup in C#

    Be Sociable, Share!
      Post Tagged with , , ,

    Written by

    View all articles by

    Email : [email protected]

    Leave a Reply