Click here to Skip to main content
13,086,662 members (60,631 online)
Rate this:
Please Sign up or sign in to vote.
See more:
private string ip()
        string strHostName = "";
        strHostName = System.Net.Dns.GetHostName();
        IPHostEntry ipEntry = System.Net.Dns.GetHostEntry(strHostName);
        IPAddress[] addr = ipEntry.AddressList;
        return addr[addr.Length - 1].ToString();

m using this code but it return

"2001:0:4137:9e76:caa:325e:3f57:fe9b" somthing like this

So what can i do for to get correct IP Address of the system
Posted 28-Nov-12 23:54pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

That looks like an IPv6 format address[^].
Dev_ashish 29-Nov-12 6:17am
Thanks Richard MacCutchan for ur response but my problem create when m log on from diff computer's it return same answer..
Richard MacCutchan 29-Nov-12 6:34am
What do you expect? It gets the local hostname and returns the IP address in either IPv4 or IPv6 format, according to which type is in use.
Dev_ashish 29-Nov-12 6:38am
i want when m log in from different host then it should return diff IP Address...
Richard MacCutchan 29-Nov-12 6:49am
It does not matter where you login from you are only asking for the address of your local machine.

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 |
Web04 | 2.8.170813.1 | Last Updated 29 Nov 2012
Copyright © CodeProject, 1999-2017
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