Click here to Skip to main content
15,893,594 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Dear Friends,

I have to show the user Machine IP on my website from which they are accessing the Website. Like in way2sms.com website from which IP your are accessing the website it shows that you are logged on from this IP.

Is there any web-service for the same. Please let me know.

Thanks

Varun Sareen
Posted
Comments
Sergey Alexandrovich Kryukov 9-Dec-11 2:02am    
If you think some Web service can do it, why you cannot? This is your client, not of some other service...
--SA

You may use Request.ServerVariables["REMOTE_ADDR"] to get IP address of the Client/Users machine.

Have a look at below link for more Request.ServerVariables.

http://www.w3schools.com/asp/coll_servervariables.asp
 
Share this answer
 
C#
public static string getclientIP()
{
    string result= string.Empty;
    string ip = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
    if (!string.IsNullOrEmpty(ip))
    {
        string[] ipRange = ip.Split(',');
        int le = ipRange.Length - 1;
        result = ipRange[0];
    }
    else
    {
        result = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
    }
 
    return result;
}


HTML
If u run u will get the ip address 127.0.0.1.Here 127.0.0.1 is localhost. this means you are working on your PC. If you try other PC to use your app, you will get a different ip address.what i mean is host your application in your IIS or on your server and another pc must use your application. with that, you will get a different IP. 127.0.0.1 is localhost, meaning, current IP address.
 
Share this answer
 
v2
Comments
Dalek Dave 9-Dec-11 4:49am    
Good Answer.

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