zoukankan      html  css  js  c++  java
  • 获取用户IP地址,防钓鱼

    为了防止网站钓鱼,我们需要对用户的IP地址进行分析处理,可是用户也有可能通过代理方式进行操作,那么该如何获取到用户的IP地址呢?

    摘自网络上的代码:

     1 public static String getClientIP(HttpServletRequest httpservletrequest) {
     2    if (httpservletrequest == null)
     3       return null;
     4    String s = httpservletrequest.getHeader("X-Forwarded-For");
     5    if (s == null || s.length() == 0 || "unknown".equalsIgnoreCase(s))
     6       s = httpservletrequest.getHeader("Proxy-Client-IP");
     7    if (s == null || s.length() == 0 || "unknown".equalsIgnoreCase(s))
     8       s = httpservletrequest.getHeader("WL-Proxy-Client-IP");
     9    if (s == null || s.length() == 0 || "unknown".equalsIgnoreCase(s))
    10       s = httpservletrequest.getHeader("HTTP_CLIENT_IP");
    11    if (s == null || s.length() == 0 || "unknown".equalsIgnoreCase(s))
    12       s = httpservletrequest.getHeader("HTTP_X_FORWARDED_FOR");
    13    if (s == null || s.length() == 0 || "unknown".equalsIgnoreCase(s))
    14       s = httpservletrequest.getRemoteAddr();
    15    if ("127.0.0.1".equals(s) || "0:0:0:0:0:0:0:1".equals(s))
    16       try {
    17          s = InetAddress.getLocalHost().getHostAddress();
    18       }catch (UnknownHostException uhe) { 
    19 uhe.printStackTrace();
    20 }
    21 return s; 22 }
  • 相关阅读:
    linux umask使用详解
    Linux 解压压缩命令
    linux命令:tail 命令
    linux命令:head 命令
    linux下cat命令详解
    linux命令:rm 命令
    linux命令:mv命令
    Linux 的cp命令
    文件权限详解
    Linux ls命令参数详解
  • 原文地址:https://www.cnblogs.com/orientsun/p/2610088.html
Copyright © 2011-2022 走看看