jsp获取ip使用request.getRemoteAddr返回0:0:0:0:0:0:0:1
JAVA Web开发过程中,很多场景下需要获取访问终端的IP,对应方法getRemoteAddr。例如调试过程中本地回环ip地址是127.0.0.1,忽然有一天返回
0:0:0:0:0:0:0:1,这个是IPv6地址,是不是会让人蒙圈。当前互联网环境下仍以ipv4为主,大家习惯接受的ipv4地址。
具体原因是因为开发者使用了高版本的操作系统,Win7/Win10等启用了ipv6,大家需要手工禁止,或者通过参数控制。
常用方法
方法1:修改server.xml
<Connector port="8083" protocol="org.apache.coyote.http11.Http11NioProtocol" address="0.0.0.0"
connectionTimeout="20000"
redirectPort="8443" />
其中address="0.0.0.0"为后添加部分
方法2(没详细验证): windows
netsh interface teredo set state disabled
netsh interface ipv6 6to4 set state state=disabled undoonstop=disabled
netsh interface ipv6 isatap set state state=disabled netsh interface IPV6 set global randomizeidentifier=disabled
netsh interface IPV6 set privacy state=disable
netsh interface ipv6 6to4 set state state=disabled
netsh interface ipv6 isatap set state state=disabled
netsh interface ipv6 set teredo=disabled
方法3:
在jvm命令行添加以下参数
-Djava.net.preferIPv4Stack=true
linux下禁用ipv6的方法
打开配置文件/etc/sysctl.d/99-sysctl.conf,在下面添加
net.ipv6.conf.all.disable_ipv6 =
net.ipv6.conf.default.disable_ipv6 =
net.ipv6.conf.lo.disable_ipv6 =
执行 sysctl -p 使配置生效
查看是否生效
cat /proc/sys/net/ipv6/conf/all/disable_ipv6
返回结果如果是1表示禁用
jsp获取ip使用request.getRemoteAddr返回0:0:0:0:0:0:0:1的更多相关文章
- Java获取IP地址:request.getRemoteAddr()注意
在JSP里,获取客户端的IP地址的方法是:request.getRemoteAddr() ,这种方法在大部分情况下都是有效的.但是在通过了Apache,Squid等反向代理软件就不能获取到客户 ...
- .net获取IP和MAC地址
获取IP 解决request.UserHostAddress取不到真实IP private string GetClientIP() { string result = HttpConte ...
- ASP.NET获取IP的6种方法
服务端: //方法一 HttpContext.Current.Request.UserHostAddress; //方法二 HttpContext.Current.Request.ServerVari ...
- 利用Java获取ip地址
方法1 public static String getIp2(HttpServletRequest request) { String ip = request.getHeader("X- ...
- get_client_ip() 获取IP地址
get_client_ip()获取ip地址,在开启IPv6协议的主机上会全部返回0.0.0.0原因是他会把ipv6地址认为是非法地址而转换成0.0.0.0,而ipv4地址在ipv6主机上用get_cl ...
- C#获取IP和主机名
System.Net.IPAddress addr; //获取IP addr = new System.Net.IPAddress ( Dns.GetHostByName ( Dns.GetHostN ...
- django获取ip与数据重复性判定
获取ip if request.META.has_key('HTTP_X_FORWARDED_FOR'): ip_c = request.META['HTTP_X_FORWARDED_FOR'] el ...
- 解决request.getRemoteAddr()获取的值为0:0:0:0:0:0:0:1这个小问题
症状: Windows操作系统,eclipse开发环境下,在本机上使用http://localhost:8080/...访问本机上的页面,使用tomcat作为服务器 在Servlet或者Action中 ...
- request.getRemoteAddr() 获取的值为0:0:0:0:0:0:0:1的原因及解决办法
问题: 在近期开发的javaweb项目中,需要记录登录时的电脑ip地址和主机名,通过request.getRemoteAddr()和request.getRemoteHost()得到的值都是0:0:0 ...
随机推荐
- centos7启动iptables时报Job for iptables.service failed because the control process exited with error cod
centos7启动iptables时报Job for iptables.service failed because the control process exited with error cod ...
- LeetCode OJ 49. Group Anagrams
题目 Given an array of strings, group anagrams together. For example, given: ["eat", "t ...
- HP LaserJet MFP M227-M231 scan use manual
HP LaserJet MFP M227-M231 scan use manual By xiangrikui 2018-10-10 Start menu/Right click Settings/ ...
- js中基本事件的总结,onclick、onblur、onchange等
js中的基本事件总结: 特定的场景下发生的一个动作:事件:事件=函数(),事件发生会触发函数执行. 属性 当以下情况发生时,出现此事件 FF N IE onabort 图像加载被中断 1 3 4 on ...
- Choosing the Type at Runtime
[Choosing the Type at Runtime] You cannot use a general expression as the React element type. If you ...
- Eclipse kepler 安装 Dynamic Web Project差距WTP
原文地址:http://blog.csdn.net/westrain2010/article/details/25122999, 欢迎转载 Eclipse 标准版是不能创建 Dynamic Web P ...
- apache服务器伪静态配置说明
apache服务器伪静态配置说明: 第一种 .如果是多城市版分类并且使用了城市二级域名即(多城市+多域名),请修改apache的配置文件,把以下代码添加到配置文件的最后一行即可,注意把qibosoft ...
- 让Ubuntu可以压缩/解压缩RAR文件
ubuntu刚安装的时候是不能解压rar文件的,只有在安装了解压工具之后,才可以解压. 安装:sudo apt-get install unrar卸载:sudo apt-get remove unra ...
- CentOS Find命令
find命令用来在指定目录下查找文件.任何位于参数之前的字符串都将被视为欲查找的目录名.如果使用该命令时,不设置任何参数,则find命令将在当前目录下查找子目录与文件.并且将查找到的子目录和文件全部进 ...
- Python __import__() 函数
Python OS 文件/目录方法 Python 面向对象 Python __import__() 函数 Python 内置函数 描述 __import__() 函数用于动态加载类和函数 . 如 ...