Resolve a host name or IP address to an IPHostEntry instance in CSharp

Description

The following code shows how to resolve a host name or IP address to an IPHostEntry instance.

Example


//from  w  w  w . j  av a  2 s  . c o  m
using System;
using System.Net;

public class MainClass
{
    public static void Main(String[] argv)
    {
        IPHostEntry host;

        host = Dns.GetHostEntry("google.com");

        foreach (IPAddress ip in host.AddressList)
        {
            Console.WriteLine("    {0}", ip);
        }
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    Network »




IP
Web Client