Ip address of the client machine

Posted by Zerotoinfinite on Stack Overflow See other posts from Stack Overflow or by Zerotoinfinite
Published on 2010-04-19T18:58:02Z Indexed on 2010/04/19 19:03 UTC
Read the original article Hit count: 505

Filed under:
|

Hi,

Please let me know how to get the client IP address,

I have tried all of the below things , but I am getting the same output 127.0.0.1

string strClientIP; strClientIP = Request.UserHostAddress.ToString();

    string strHostName = System.Net.Dns.GetHostName();
    string clientIPAddress = System.Net.Dns.GetHostAddresses(strHostName).GetValue(0).ToString();


     string ipaddress = string.Empty ;
    ipaddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
    if (ipaddress == "" || ipaddress == null)
        ipaddress = Request.ServerVariables["REMOTE_ADDR"];

Please tel me how can I get the correct IP !

© Stack Overflow or respective owner

Related posts about ipaddress

Related posts about ASP.NET