日期:2014-05-19  浏览次数:20707 次

获取本机外网IP
外网访问,需要取得访问者的IP,好做限制。
j2EE技术,tomcat网络服务器

------解决方案--------------------
探讨

你是要获得你自己的

还是别人访问你的过程中别人的

获得自己的访问ip138

如果是对客户端的话 http://www.iteye.com/problems/66461

------解决方案--------------------
/*
* 获取IP地址
*/
public static 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;
}


String remoteIp=getIpAddr;