+ Reply to Thread
Results 1 to 2 of 2

Thread: get the ip address of a domain name & also get hostname of ip

  1. #1

    get the ip address of a domain name & also get hostname of ip

    I'd like to know how to get the IP of a domain name and also convert the IP of a website to a hostname in C#

    Thanks in advance.
    Last edited by csharpmaster; 11-01-2012 at 01:56 PM.

  2. #2
    Junior Member
    Join Date
    Jan 2012
    Posts
    45
    1) Getting the IP address of a website :
    Code:
                string hostname = "google.com";
                IPAddress[] addresslist = Dns.GetHostAddresses(hostname);
                foreach (IPAddress theaddress in addresslist)
                {
                    Console.WriteLine(theaddress.ToString());
                }
    2) Converting the IP address into a hostname
    Code:
                IPHostEntry iph = new IPHostEntry();
                iph = Dns.GetHostByAddress("127.0.0.1");
                Console.WriteLine(iph.HostName);

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts