IP address from host name
In this chapter you will learn:
Get IP address from host name
using System;// j ava2 s .c om
using System.Net;
class MainClass
{
public static void Main()
{
IPHostEntry ihe = Dns.GetHostByName(Dns.GetHostName());
IPAddress myself = ihe.AddressList[0];
Console.WriteLine(myself);
}
}
The code above generates the following result.
Get Host by IP address
using System;/* java 2 s. 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);
Console.WriteLine("Information for {0}", test.ToString());
Console.WriteLine("Host name: {0}", iphe.HostName);
}
}
The code above generates the following result.
Next chapter...
What you will learn in the next chapter:
Home » C# Tutorial » Network