Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: WinForm
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
good
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: http://www.whatsmyip.org/[^] is one such service you can ask.
  Permalink  
Rate this: bad
good
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("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.
 
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.
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 400
1 Jochen Arndt 190
2 Richard MacCutchan 135
3 DamithSL 95
4 Garth J Lancaster 90
0 OriginalGriff 6,045
1 DamithSL 4,601
2 Maciej Los 4,032
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,220


Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 26 Feb 2013
Copyright © CodeProject, 1999-2014
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