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 }
  • 相关阅读:
    第五周总结
    10.24号进度报告
    10.23日进度报告
    10.22日进度报告
    10.21日进度报告
    10.20号进度总结
    10.19日进度总结
    第四周总结
    10.18日进度博客
    2020下第六周总结
  • 原文地址:https://www.cnblogs.com/orientsun/p/2610088.html
Copyright © 2011-2022 走看看