Click here to Skip to main content
15,885,124 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
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

1 solution

That looks like an IPv6 format address[^].
 
Share this answer
 
Comments
Dev Ashish Jangid 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 Jangid 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)



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