Friday, March 7, 2008

How to get IP Address of a computer in C#

To get the IP address of the local machine in C#, namespace is needed. From the IPHostEntry class, we can get the address list in a string array.

using System.Net;
private string GetIP() {
     string strHostName = "";
     strHostName = System.Net.Dns.GetHostName();
     IPHostEntry ipEntry = System.Net.Dns.GetHostEntry(strHostName);
     IPAddress[] addr = ipEntry.AddressList;

     return addr[addr.Length-1].ToString();


Anonymous said...

Thanks for giving the program to know the ip address.
But i know my ip address through this ip-details along with router map.


Get paid for your opinions! Click on the banner above to join Planet Pulse. Its totally free to sign up, and you can earn UNLIMITED. Find out more by visiting PLANET PULSE.
July Code Blog Copyright © 2010 Blogger Template Designed by Bie Blogger Template