0

Hello I am trying to fetch IP. My application is running on Microsoft Azure so remoteIpAddr and remoteHost is saving Azure Frontdoor IP. Whereas ipAddress is null .. How to fetch the Client's IP ? How to know which header has that ?

Below is the code I am using

String remoteIpAddr = request.getRemoteAddr();
String remoteHost = request.getRemoteHost();
String ipAddress = request.getHeader("X-FORWARDED-FOR");
2
  • When your application is behind Azure Front Door, the client's original IP address is typically included in the X-Forwarded-For HTTP header. However, if this header is missing or null in your case, you should also check for the X-Azure-ClientIP header, which Azure uses to pass the client's IP. Here's how you can modify your code to fetch the client's IP address effectively:
    – Vinay B
    Commented May 2 at 16:37
  • 1
    String ipAddress = request.getHeader("X-Forwarded-For"); if (ipAddress == null) { ipAddress = request.getHeader("X-Azure-ClientIP"); // Check for Azure specific header } This will first try to get the IP from X-Forwarded-For and if not available, it will fall back to X-Azure-ClientIP.
    – Vinay B
    Commented May 2 at 16:37

1 Answer 1

0

Have a look into this.

https://learn.microsoft.com/en-us/azure/frontdoor/front-door-faq#does-azure-front-door-preserve--x-forwarded-for--headers-

You need to look for all three X-Forwarded-For, X-Forwarded-Host, and X-Forwarded-Proto headers

Not the answer you're looking for? Browse other questions tagged or ask your own question.