• java获取本机ip地址(写出来的)


    /**
    * @author 豪弟
    * @param request
    * @return
    * @throws IOException
    */
    public final static String getIpAddress(HttpServletRequest request)
    throws IOException {
    // 获取请求主机IP地址,如果通过代理进来,则透过防火墙获取真实IP地址

    String ip = request.getHeader("X-Forwarded-For");

    if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
    if (ip == null || ip.length() == 0
    || "unknown".equalsIgnoreCase(ip)) {
    ip = request.getHeader("Proxy-Client-IP");
    }
    if (ip == null || ip.length() == 0
    || "unknown".equalsIgnoreCase(ip)) {
    ip = request.getHeader("WL-Proxy-Client-IP");
    }
    if (ip == null || ip.length() == 0
    || "unknown".equalsIgnoreCase(ip)) {
    ip = request.getHeader("HTTP_CLIENT_IP");
    }
    if (ip == null || ip.length() == 0
    || "unknown".equalsIgnoreCase(ip)) {
    ip = request.getHeader("HTTP_X_FORWARDED_FOR");
    }
    if (ip == null || ip.length() == 0
    || "unknown".equalsIgnoreCase(ip)) {
    ip = request.getRemoteAddr();
    }
    } else if (ip.length() > 15) {
    String[] ips = ip.split(",");
    for (int index = 0; index < ips.length; index++) {
    String strIp = (String) ips[index];
    if (!("unknown".equalsIgnoreCase(strIp))) {
    ip = strIp;
    break;
    }
    }
    }
    return ip;
    }

  • 相关阅读:
    SFDC_08(翻页功能)
    SFDC-07(图形)
    SFDC_06(Data Loader)
    SFDC_05(内部类)
    SFDC_03(覆盖率)
    vue项目搭建
    vue语法01
    IDEA 的逆向工程 mybatis generate tool 的使用
    Git: Git: There is no tracking information for the current branch.
    Tomcat 不一定 需要配置环境变量(startup.bat 闪退原因及解决办法)
  • 原文地址:https://www.cnblogs.com/lqh-haodi/p/10727469.html
Copyright © 2020-2023  润新知