六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 99|回复: 0

获得客户端IP

[复制链接]

升级  8%

16

主题

16

主题

16

主题

秀才

Rank: 2

积分
62
 楼主| 发表于 2013-2-7 20:57:53 | 显示全部楼层 |阅读模式
版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明
http://fendechen.blogbus.com/logs/24955413.html



String IP = httpRequest.getHeader("x-forworded-for");
  if (IP != null && IP.length() != 0) {
   while ((IP != null) && (IP.equals("unknow"))) {

    IP = httpRequest.getHeader("x-forworded-for");
   }
  }

  if (IP == null || IP.length() == 0) {
   IP = httpRequest.getHeader("Proxy-Client-IP");
  }

  if (IP == null || IP.length() == 0) {
   IP = httpRequest.getHeader("WL-Proxy-Client-IP");
  }

  if (IP == null || IP.length() == 0) {
   IP = httpRequest.getRemoteAddr();
  }
  // 得到访问者所在网段
String  subIP = IP.substring(0, IP.lastIndexOf("."));
  
  System.out.println("真实的IP地址:" + IP+"网段是:"+subIP);
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表