Servlet上的主机IP地址0:0:0:0:0:0:0:1 [英] Host IP Address 0:0:0:0:0:0:0:1 on Servlet

查看:341
本文介绍了Servlet上的主机IP地址0:0:0:0:0:0:0:1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用以下方式获取用户的主机,IP和端口:

I am trying to get the user Host, IP, and Port using:

request.getRemoteHost()
request.getRemoteAddr()
request.getRemotePort()

但是我得到了:

主机: 0:0:0:0:0:0:0:1
IP:地址为空
端口: 51111

Host: 0:0:0:0:0:0:0:1
IP: Address null
Port: 51111

如何获得正确的IP地址,请注意我们的网络IP以10.100.x.x开头

How do I get the correct IP address, noting that our network IP start with 10.100.x.x

非常感谢.

推荐答案

如果在请求URI中使用localhost,则IPv6为0:0:0:0:0:0:0:1.代替使用localhost,在请求URI中使用IPv4以获得正确的 IP.

If you are using the localhost in your request URI, then the IPv6 is 0:0:0:0:0:0:0:1. Instead of using localhost, use your IPv4 in your request URI to get the correct IP.

这篇关于Servlet上的主机IP地址0:0:0:0:0:0:0:1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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