Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8971965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:05:46+00:00 2026-06-15T18:05:46+00:00

In my web application I need to extract the real ip address for clients

  • 0

In my web application I need to extract the real ip address for clients behind proxy, after searching I found that the possible method to do that is to read the content of “X_FORWARDED_FOR” header , I am using java servlet and the headers of the incoming request doesn’t contain “X_FORWARDED_FOR” header , So why the header doesn’t included in the request?

I am using java 1.7 , tomcat v7 , proxy server :TMG and configured to use “X_FORWARDED_FOR” header .

Please advice.

Thanks in advance.

Update :

  • The request come from jquery ajax request to servlet.
  • My code to read available headers:

    String ip = request.getHeader("X-Forwarded-For"); //return null

            if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {  
                ip = request.getHeader("Proxy-Client-IP");  //return null
            }  
            if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {  
                ip = request.getHeader("WL-Proxy-Client-IP");  //return null
            }  
            if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {  
                ip = request.getHeader("HTTP_CLIENT_IP");  //return null
            }  
            if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {  
                ip = request.getHeader("HTTP_X_FORWARDED_FOR");  //return null
            }  
            if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {  
                ip = request.getRemoteAddr();  //return proxy server IP
            }  
    
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T18:05:47+00:00Added an answer on June 15, 2026 at 6:05 pm

    X-Forwarded-For, as well as other headers you test, are custom (it is almost standard, but not quite). Proxy doesn’t have to set any such header, so you’ll have to test which header the proxy server will set, if any.

    However, if it would be set, you’d test it with

    request.getHeader("X-Forwarded-For");
    

    HTTP_X_FORWARDED_FOR would be PHP naming, don’t use that if you’re not using PHP…

    I would iterate all incoming headers and see if any header contains the ip. If none of them do, you’re out of luck.

    You can iterate all headers with

    enames = request.getHeaderNames();
    while (enames.hasMoreElements()) {
      String name = (String) enames.nextElement();
      String value = request.getHeader(name);
      // "name" and "value" variables contain the header + its value
    }
    

    Also note that for java apps, it is often that what gets passed to the servlet is an inner request, and you need to ask for outer request first to get an instance of httpservletrequest that has the headers.

    Note also that even if you actually get an ip from that header, you should still think if that is usable information or not. some more details about it here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a web application that will need to access code behind methods as
I'm writing a web application and need to initialize some parameters that I'm pulling
I am building a web application that will need to allow users to save
There is this DB-connection-like object that my web application will need. It is pretty
I am working on a Python/django web application and I need to extract text
So, here's a quick extract of the directory structure on a web application that
In the java web application need to select the file from server and print
For my web application I need to close the child window whenever the parent
I'm working on a web application and need some help with a query. I'm
I'm writing a web application where I need to pass some user data to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.