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#, system.net 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();
}

1 comments:

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.
Sign up for PayPal and start accepting credit card payments instantly. http://www.emailcashpro.com
July Code Blog Copyright © 2010 Blogger Template Designed by Bie Blogger Template