Click here to Skip to main content
11,709,220 members (72,635 online)
Rate this: bad
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 21: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
0 Sergey Alexandrovich Kryukov 565
1 OriginalGriff 244
2 Maciej Los 225
3 Peter Leow 219
4 Mika Wendelius 160
0 OriginalGriff 9,348
1 Sergey Alexandrovich Kryukov 8,727
2 CPallini 5,189
3 Maciej Los 4,991
4 Mika Wendelius 3,856

Advertise | Privacy | Mobile
Web04 | 2.8.150819.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