获取真实IP的工具类
来源:互联网 发布:机械公差查询软件 编辑:程序博客网 时间:2024/06/04 23:28
package com.easyssh.framework.utils;
import java.util.*;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class IpUtils
{
{
public IpUtils()
{
}
{
}
public static String getClientIp(HttpServletRequest request)
{
String ip = request.getHeader("x-forwarded-for");
if(LOG.isDebugEnabled())
LOG.debug("x-forwarded-for = {}", ip);
if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip))
{
ip = request.getHeader("Proxy-Client-IP");
if(LOG.isDebugEnabled())
LOG.debug("Proxy-Client-IP = {}", ip);
}
if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip))
{
ip = request.getHeader("WL-Proxy-Client-IP");
if(LOG.isDebugEnabled())
LOG.debug("WL-Proxy-Client-IP = {}", ip);
}
if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip))
{
ip = request.getRemoteAddr();
if(LOG.isDebugEnabled())
LOG.debug("RemoteAddr-IP = {}", ip);
}
if(StringUtils.isNotEmpty(ip))
ip = ip.split(",")[0];
return ip;
}
{
String ip = request.getHeader("x-forwarded-for");
if(LOG.isDebugEnabled())
LOG.debug("x-forwarded-for = {}", ip);
if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip))
{
ip = request.getHeader("Proxy-Client-IP");
if(LOG.isDebugEnabled())
LOG.debug("Proxy-Client-IP = {}", ip);
}
if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip))
{
ip = request.getHeader("WL-Proxy-Client-IP");
if(LOG.isDebugEnabled())
LOG.debug("WL-Proxy-Client-IP = {}", ip);
}
if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip))
{
ip = request.getRemoteAddr();
if(LOG.isDebugEnabled())
LOG.debug("RemoteAddr-IP = {}", ip);
}
if(StringUtils.isNotEmpty(ip))
ip = ip.split(",")[0];
return ip;
}
public static boolean ipMatch(String ip, String ips[])
{
if(ips == null || ips.length == 0)
throw new IllegalArgumentException("ips is null or emtpy");
boolean f = false;
List list = new ArrayList();
for(int i = 0; i < ips.length; i++)
list.add(ips[i].replaceAll("//*", "////d+").replaceAll("//.", "////."));
{
if(ips == null || ips.length == 0)
throw new IllegalArgumentException("ips is null or emtpy");
boolean f = false;
List list = new ArrayList();
for(int i = 0; i < ips.length; i++)
list.add(ips[i].replaceAll("//*", "////d+").replaceAll("//.", "////."));
Iterator i$ = list.iterator();
do
{
if(!i$.hasNext())
break;
String e = (String)i$.next();
if(!ip.matches(e))
continue;
f = true;
break;
} while(true);
return f;
}
do
{
if(!i$.hasNext())
break;
String e = (String)i$.next();
if(!ip.matches(e))
continue;
f = true;
break;
} while(true);
return f;
}
protected static final Logger LOG = LoggerFactory.getLogger(com/easyssh/framework/utils/IpUtils);
}
- 获取真实IP的工具类
- 获取真实的IP地址
- 获取来访者的真实IP
- 获取真实的IP地址
- 获取客户端的真实ip
- 获取真实的客户IP
- 获取客户端真实的ip
- 获取用户的真实ip
- 获取客户端的真实ip
- 获取Ip的工具类
- 获取ip的工具类
- 关于httpservletrequest的获取真实的ip
- httpservletrequest的获取真实的ip
- ASP获取真实的IP地址
- 获取客户端的真实IP地址
- java如何获取真实的IP
- 获取远程客户端的真实IP地址
- 获取客户端真实IP的方法
- SPI总线简介
- 金蝶中间件2011校招笔试题
- Java动态代理
- 【转贴】Java中关于原子操作和volatile关键字
- MD5
- 获取真实IP的工具类
- 用表驱动代替switch-case
- vs2010调试H.264测试模型还要注意的方面
- SIFT算法的教程、源码及应用软件
- MD5
- 人啊,就要对自己狠一点!
- 浮点数在内存中的存储形式(转载)
- MD5
- 利用htmlparser抓取网页内容