使用request.getRemoteAddr()返回0:0:0:0:0:0:0:1 [英] Using request.getRemoteAddr() returns 0:0:0:0:0:0:0:1

查看:713
本文介绍了使用request.getRemoteAddr()返回0:0:0:0:0:0:0:1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的webApplication中打印已登录用户的IP地址。如果用户使用IP地址 192.168.10.120:8080/WebApplication 连接另一台PC(位于同一网络下,因为Web应用程序在我的电脑上运行)代码 request.getRemoteAddr() request.getLocalAddr())返回其IP地址。当我从运行Web应用程序的PC登录时,我得到的IP地址为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!

推荐答案

在你的情况下,as您正尝试在本地计算机上访问它,因此它将返回该值。但是让你的一个朋友访问它,你将收到预期的结果 getRemoteAddr

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

来自javadoc:

From the javadoc:

getRemoteAddr - 返回发送请求的客户端或最后一个代理的IP地址

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

getLocalAddr - 返回收到请求的接口的IP地址。

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

这篇关于使用request.getRemoteAddr()返回0:0:0:0:0:0:0:1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆