透过代理获取真实IP

public String getIpAddr(HttpServletRequest request) {
String strClientIp = request.getHeader("x-forwarded-for");
log.info("All the IP address string is: " + strClientIp);
if(strClientIp == null || strClientIp.length() == 0 ||"unknown".equalsIgnoreCase(strClientIp))
{
    strClientIp = request.getRemoteAddr();
}else{
    StringList ipList = new StringList();
    BusiAcceptAction.SplitsString(strClientIp, ',' , ipList); // 拆分字符串,可直接用String.plit方法
    String strIp = new String();
    for(int index = 0; index < ipList.size(); index ++)
    {
        strIp = (String)ipList.get(index);
        if(!("unknown".equalsIgnoreCase(strIp)))
        {
            strClientIp = strIp;
            break;
        }
    }
}

return strClientIp;
}

你可能感兴趣的:(代理,IP)