Reputation: 231
Cloudflare provides a number of solutions to retain the original client's IP address, but mostly it is for people who own access to the physical box or have IaaS.
For Google app engine, how can I make it work with Cloudflare such that I still can extract the original client's IP address?
Upvotes: 2
Views: 1487
Reputation: 734
According to cloudflare support they are setting a header: CF-Connecting-IP
.
To retrieve this header in java you can use
String paramIpAddress = request.getHeader("CF-Connecting-IP");
if (paramIpAddress == null) {
paramIpAddress = request.getRemoteAddr();
}
Upvotes: 3
Reputation: 1276
You can also use HTTP_X_FORWARDED_FOR to get the "real" IP. It appears you can get at that in Java using these details:
String ipaddress = request.getHeader("HTTP_X_FORWARDED_FOR");
if (ipaddress == null)
ipaddress = request.getRemoteAddr();
Source = http://thepcspy.com/read/getting_the_real_ip_of_your_users/
Related and might be helpful: http://www.coderanch.com/t/293684/JSP/java/client-IP-address-Domain-Java
Upvotes: 2
Reputation: 1457
You can use the following server variables:
$_SERVER["HTTP_CF_CONNECTING_IP"] Real visitor IP address
$_SERVER["HTTP_CF_IPCOUNTRY"] Country of visitor
$_SERVER["HTTP_CF_VISITOR"] If its HTTP or HTTPS
Below is the sample codes in PHP:
if (isset($_SERVER["HTTP_CF_CONNECTING_IP"])) {
$_SERVER['REMOTE_ADDR'] = $_SERVER["HTTP_CF_CONNECTING_IP"];
}
Upvotes: 0