localhost与本机IP访问tomcat出现IPV6和IPV4两种结果
我用localhost访问时 获得IP为0:0:0:0:0:0:0:1,百度得知是IPV6形式,用本机IP访问时获得IP为正常IPV4,可是我现在只想获得IPv4形式的IP地址,第一不能
public String getIpAddr(HttpServletRequest request) {
String ip = request.getHeader("x-forwarded-for");
if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("Proxy-Client-IP");
}
if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("WL-Proxy-Client-IP");
}
if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getRemoteAddr();
}
return ip;
} ,因为我没有request,第二不能修改C:\Windows\system32\drivers\etc\ hosts 有没有办法,我使用的是tomcat7 tomcat7 address spring?mvc IPv6 IPv4
[解决办法]
我不明白你的程序跑在公网还是你本地电脑
[解决办法]
跑在你电脑上,百度得知是什么意思
[解决办法]
你的localhost 对应的ip是什么
还是要看host设置