Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using request.getRemoteAddr() returns 0:0:0:0:0:0:0:1

Tags:

java

jsp

servlets

I am trying to print the IP adress of the logged user in my webApplication. If a user connects from another PC (which is under the same network, as the web application is running in my pc) using the IP address 192.168.10.120:8080/WebApplication the code request.getRemoteAddr() or request.getLocalAddr()) returns his IP address. When I log in from my pc which run the web application, I get this IP address 0:0:0:0:0:0:0:1.

Why is that? And what's the difference between these commands (which should I use?).Thank you a lot!

like image 882
yaylitzis Avatar asked Jul 31 '13 07:07

yaylitzis


People also ask

What is request getRemoteAddr ()?

getRemoteAddr - Returns the IP address of the client or last proxy that sent the request. getLocalAddr - Returns the IP address of the interface on which the request was received.

How do I find my spring boot client IP address?

From Spring Tool Suite IDE select menu File > New > Spring Starter Project. On the New Spring Starter Project popup input new project spring-boot-client-ip information as following screenshot. On the New Spring Starter Project Dependencies popup choose Thymeleaf and Spring Web dependency as below screenshot.


2 Answers

In your case, as you are trying to access it on your local machine,so it will return that value. But let one of your friend access it, and you will receive the expected result with getRemoteAddr

From the javadoc:

getRemoteAddr - Returns the IP address of the client or last proxy that sent the request

getLocalAddr - Returns the IP address of the interface on which the request was received.

like image 152
Abubakkar Avatar answered Sep 18 '22 17:09

Abubakkar


As we move over to IPv6 from IPv4, they are changing the loopback address (localhost) to 0:0:0:0:0:0:0:1 from 127.0.0.1 thats why you are getting this address.

As for the functions:

  • getRemoteAddr() returns the clients IP

  • getLocalAddr() returns the IP of the server the application is running on

like image 38
Robert Pounder Avatar answered Sep 18 '22 17:09

Robert Pounder