Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Remote user IP Address  RSS feed

 
Henrique Ordine
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone,

I'm using request.getRemoteAddr() in my servlet and it returns "127.0.0.1" to me, not the actual IP address. I need tha actual IP address. I'm accessing the Servlet from the same machine where the J2EE server is running. Could anyone please tell me what the problem is?
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does it return if you access the server from some other machine?
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you access it via http://localhost you get the loop back IP, if you use the machine name ie http://machinename then you get the machine IP
 
Deepan Devadasan
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That was useful to me as well
 
Henrique Ordine
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks David, you're right!
Ulf, from another machine, it returned the machine's ip address.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This trick is handy when testing IP-specific code. We had specific code for Kiosks running on fixed addresses. If you register one IP in your app then you can send requets and test the code works correctly.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!