/**
* @Title: getIpAddr
* @author kaka
* @Description: 获取客户端IP地址
* @param @return
* @return String
* @throws
*/
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();
if(ip.equals("127.0.0.1")){
//根据网卡取本机配置的IP
InetAddress inet=null;
try {
inet = InetAddress.getLocalHost();
} catch (UnknownHostException e) {
e.printStackTrace();
}
ip= inet.getHostAddress();
}
}
// 对于通过多个代理的情况,第一个IP为客户端真实IP,多个IP按照','分割
if(ip != null && ip.length() > 15){
if(ip.indexOf(",")>0){
ip = ip.substring(0,ip.indexOf(","));
}
}
return ip;
}
最近下载更多
丹丹 LV1
2021年11月24日
junq-G LV2
2021年5月26日
听雨轩丿 LV10
2021年5月5日
joyceloo LV1
2021年3月12日
jiong521968 LV1
2020年11月28日
GFC0011 LV1
2020年6月7日
LIFANG123 LV1
2020年1月28日
lyd19931203 LV21
2019年7月22日
1024508706 LV2
2019年3月22日
zoumuhao LV2
2019年1月26日

最近浏览