Click here to Skip to main content
11,925,307 members (64,253 online)
Rate this:
Please Sign up or sign in to vote.
See more: (untagged)
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 25-Feb-13 22:37pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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:[^] is one such service you can ask.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

What programming language do use.

Example for C#.Net
Try this function to get your public IP
public string GetPublicIP()
    String direction = "";
    WebRequest request = WebRequest.Create("");
    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.

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.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.151126.1 | Last Updated 26 Feb 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100