Click here to Skip to main content
15,918,275 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,I want to get system IP address in which my window application is installed...can it be possible in window form application??

smeone help me plzz...

Thanks in advance..
Posted

Depends which IP address you are after.
If you want the IP address of your PC on the LAN, then that is pretty easy: Retrieving IP and MAC addresses for a LAN[^] covers it, just use the GetIPAddress method and ignore the rest.

If you want your IP address that you present to the outside world via teh internet, then that is more complex - it isn't related to your PC, but to your Router and doesn't come into the LAN at all. So you have to ask an external service for the value: http://www.whatsmyip.org/[^] is one such service you can ask.
 
Share this answer
 
What programming language do use.

Example for C#.Net
Try this function to get your public IP
C#
public string GetPublicIP()
{
    String direction = "";
    WebRequest request = WebRequest.Create("http://checkip.dyndns.org/");
    using (WebResponse response = request.GetResponse())
    using (StreamReader stream = new StreamReader(response.GetResponseStream()))
    {
        direction = stream.ReadToEnd();
    }

    //Search for the ip in the html
    int first = direction.IndexOf("Address: ") + 9;
    int last = direction.LastIndexOf("</body>");
    direction = direction.Substring(first, last - first);

    return direction;
}


and try this function to get your local IP.

C#
public string GetLocalIP(){
return Dns.GetHostEntry(Dns.GetHostName()).AddressList.FirstOrDefault(ip => ip.AddressFamily == AddressFamily.InterNetwork) ?? new IPAddress( new byte[] {127, 0, 0, 1} );
}


Hope this helps.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900