How to get the IP address of the machine of the user

When we are logging the website we also want to log the user IP address.

The below given code gives you the IP address of the User Accessing the site.

HttpContext.Current.Request.UserHostAddress;
or
HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];

To get the IP address of the machine and not the proxy use the following code

HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];

Hope this helps
Thanks
Vikram


Share this post   Email it |  digg it! |  reddit! |  bookmark it!

Feedback

Posted on 11/18/2007 12:11:06 AM

how to block the internet of network client computer

Posted on 12/4/2008 5:56:22 PM

It works! Thanks.

Posted on 1/5/2009 11:56:35 PM

Great^^

Please post your comments:

Name:  
Email (optional): Your email address will not be posted.
URL (optional):
Comments: HTML will be ignored, URLs will be converted to hyperlinks  
Enter the text you see in the box:
 
Copyright © 2006 - 2009 Vikram Lakhotia