• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Can we get Remote IP Address without using HttpServletRequest?

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

Can we get Remote IP Address without using HttpServletRequest?

I have the solution like below:

public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
InetAddress remoteInetAddress = InetAddress.getByName(req.getRemoteAddr());

}

Could you please provide me any alternate solution with out using HttpServletRequest ?

Thanks & Regards
Koti
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How? The request is the *only* information you have from the client, no?
 
Ranch Hand
Posts: 493
Android Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
David is totally right , but the question here is why you wanna get Remote IP Address without using HttpServletRequest? !!
 
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The following code results in the output shown in comments.....



Thus none of these methods have useable information.

How can I get a real IP address Gets no useable data.... Why ? I need the users ip address for logging purposes... And I recall the "getRemoteAddr())" method as working.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In Tomcat server.xml there is an "enableLookups" setting - set this to true and see what happens.

The comments in server.xml explain it all.

Bill
 
Saloon Keeper
Posts: 27764
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Knowing a source IP address is not generally all that useful, since there's the remote client's actual IP address and then there's the IP address(es) of one or more intermediary proxies and NAT services. Headers attempt to recover some of that information, but headers can be forged or tampered with, and not all intermediaries may even inject headers.

In any event, Jay's attempt to manually log was questionable itself, since Tomcat does have a Valve that can do that sort of thing so there's little need to write application code for that. The Tomcat log, however, will list the latest IP address in the chain, which is the only one that's actually reliable, since TCP/IP cannot work with a fake address in the packet header. UDP can be spoofed - and often is for things like nameserver DDOS, but Tomcat doesn't use UDP protocols.
 
reply
    Bookmark Topic Watch Topic
  • New Topic