• IP地址的获取


    //ip地址的获取:非原创,之前在其他地方看到,拿过来备份下:

    public static String getIPAddress(HttpServletRequest request) {
            String ip = null;
            String ipAddresses = request.getHeader("X-Forwarded-For");
            if(ipAddresses == null || ipAddresses.length() == 0 || "unknown".equalsIgnoreCase(ipAddresses)) {
                ipAddresses = request.getHeader("Proxy-Client-IP");
            }
    
            if(ipAddresses == null || ipAddresses.length() == 0 || "unknown".equalsIgnoreCase(ipAddresses)) {
                ipAddresses = request.getHeader("WL-Proxy-Client-IP");
            }
    
            if(ipAddresses == null || ipAddresses.length() == 0 || "unknown".equalsIgnoreCase(ipAddresses)) {
                ipAddresses = request.getHeader("HTTP_CLIENT_IP");
            }
    
            if(ipAddresses == null || ipAddresses.length() == 0 || "unknown".equalsIgnoreCase(ipAddresses)) {
                ipAddresses = request.getHeader("X-Real-IP");
            }
    
            if(ipAddresses != null && ipAddresses.length() != 0) {
                ip = ipAddresses.split(",")[0];
            }
    
            if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ipAddresses)) {
                ip = request.getRemoteAddr();
            }
    
            return ip;
        }
  • 相关阅读:
    Python中yield和yield from区别
    Python基础05编码问题
    Python eval()函数
    Python异常大全
    Python基础08 内置函数
    Python os和sys模块基本操作
    git学习(3)-本地标签管理
    ubuntu 安装 node 以及升级更新到最新版本
    git学习(2)-分支管理
    git学习(1)-git基础
  • 原文地址:https://www.cnblogs.com/yangxiaohui227/p/11195871.html
Copyright © 2020-2023  润新知