Click here to Skip to main content
15,884,472 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Please help me!

How can I get the client's real IP address in ASP.NET page?

I have tried many ways to try to get this value, but failed.
Here is my tried methods:

C#
Request.UserHostAddress
Request.ServerVariables["HTTP_X_FORWARDED_FOR"]
Request.ServerVariables["REMOTE_ADDR"]


The result is:
C#
UserHostAddress: 16.85.175.133
HTTP_X_FORWARDED_FOR:
REMOTE_ADDR: 16.85.175.133


This is not client IP address, it's Proxy address.

Any solutions to get this value ?

Thank you!
Posted
Comments
PIEBALDconsult 11-Apr-13 10:51am    
Why? The same client's IP address could be different the next time they contact you.
Prasad Khandekar 11-Apr-13 11:09am    
In ASP.NET server side alone you won't be able to get it. See this discussion (http://superuser.com/questions/284927/how-to-get-the-real-ip-address-of-someone-using-a-proxy)
snorkie 11-Apr-13 13:33pm    
Are you asking for the public/external IP address(es), or the local LAN address(es)?

1 solution

What you mean in the IP address that is seen from outside.
To get this IP address, you must use a service that provide this information manually or programatically (via API).

For example, to use 'http://whatismyip.com' the following code will obtain the IP programatically:

C#
UTF8Encoding utf8 = new UTF8Encoding();
WebClient mywebClient = new WebClient();
String externalIp = utf8.GetString(mywebClient.DownloadData("http://whatismyip.com/automation/n09230945.asp"));

Response.Write("Your External IP Address is: " + externalIp );
 
Share this 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