Wednesday, June 3, 2009

Code for getting local Local Machine name and Ip address

The follow ing code to display the current machine name and the ip address of the current machine

This is the console program, copy the below code and put inside your main method and include the following namespace.

using System.Net;


string strHostName="";
strHostName = Dns.GetHostName();
Console.WriteLine("Local Machine's Host Name: " + strHostName);
Console.ReadLine();
IPHostEntry ientry = Dns.GetHostByName(strHostName);
IPAddress[] addr = ientry.AddressList;
for (int i = 0; i < addr.Length; i++)
{
Console.WriteLine("IP Address {0}: {1} ", i, addr[i].ToString());
}
Console.ReadLine();


Enjoy !!!

1 comment:

  1. Hai,
    Thanks for this code.I found my internet ip address in the site www.ip-details.com.From this code I get the Local machine name.Once again thanks.

    ReplyDelete