Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
232 views
in Technique[技术] by (71.8m points)

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

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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...