IPHostEntry

In this chapter you will learn:

  1. Get Alias from IPHostEntry
  2. Get IPAddress from IPHostEntry
  3. Get IPHostEntry by host name

Get Alias from IPHostEntry

using System;// j ava2 s  .  c  om
using System.Net;

class MainClass
{
   public static void Main(string[] argv)
   {
      IPAddress test = IPAddress.Parse("64.200.123.1");

      IPHostEntry iphe = Dns.GetHostByAddress(test);

      foreach(string alias in iphe.Aliases)
      {
         Console.WriteLine("Alias: {0}", alias);
      }
   }
}

Get IPAddress from IPHostEntry

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

class MainClass
{
   public static void Main(string[] argv)
   {
      IPAddress test = IPAddress.Parse("64.200.123.1");

      IPHostEntry iphe = Dns.GetHostByAddress(test);

      foreach(IPAddress address in iphe.AddressList)
      {
         Console.WriteLine("Address: {0}", address.ToString());
      }
   }
}

The code above generates the following result.

Get IPHostEntry by host name

using System;//java2s  .c  o  m
using System.Net;

class MainClass
{
   public static void Main(string[] argv)
   {
      IPHostEntry results = Dns.GetHostByName("www.java2s.com");

      Console.WriteLine("Host name: {0}",results.HostName);

      foreach(string alias in results.Aliases)
      {
         Console.WriteLine("Alias: {0}", alias);
      }
      foreach(IPAddress address in results.AddressList)
      {
         Console.WriteLine("Address: {0}",
                     address.ToString());
      }
   }
}

The code above generates the following result.

Next chapter...

What you will learn in the next chapter:

  1. Create(parse) IP address from string
Home » C# Tutorial » Network
Cookie
CredentialCache
HostEntry
IPHostEntry
IP address from host name
IPEndPoint from IPAddress
IPEndPoint Port
IPEndPoint properties
IPHostEntry
IP Address Parser
Predefined IP Address
NetworkCredential
Ping
Udp Client
Socket connection
Socket creation
Socket sendTo
TcpClient
TcpListener
UdpClient Receive
UdpClient Sending
Uri
WebClient
Response Headers
WebProxy
WebRequest