Code:
using System;
using System.Net;
namespace Program
{
class Program
{
static void Main()
{
String strHostName = string.Empty; //getting the Host Name.
strHostName = Dns.GetHostName();
Console.WriteLine("Local Machine's Host Name: " + strHostName);
IPHostEntry ipEntry = Dns.GetHostEntry(strHostName);// Using Host Name,IP address is obtained.
IPAddress[] addr = ipEntry.AddressList;
for (int i = 0; i < addr.Length; i++)
{
Console.WriteLine("IP Address {1} : ",addr[i].ToString());
}
Console.ReadLine();
}
}
}
Output:
Local Machine's Host Name : win7-pc
IP Address : 192.168.1.2
More C# Programs: