zoukankan      html  css  js  c++  java
  • Java 获取客服端ip地址

    Java 获取客服端ip地址

    /**
     * <html>
     * <body>
     *  <P> Copyright 1994 JsonInternational</p>
     *  <p> All rights reserved.</p>
     *  <p> Created on 19941115</p>
     *  <p> Created by Jason</p>
     *  </body>
     * </html>
     */
    package cn.ucaner.alpaca.framework.utils.ip;
    
    import javax.servlet.http.HttpServletRequest;
    
    /**
    * @Package:cn.ucaner.framework.utils   
    * @ClassName:IPAddress   
    * @Description:   <p> ip地址</p>
    * @Author: - Jason 
    * @CreatTime:2017年8月30日 下午2:12:19   
    * @Modify By:   
    * @ModifyTime:  
    * @Modify marker:   
    * @version    V1.0
     */
    public class IPAddress {
    	
    	/**
    	 * 获取客户端ip地址
    	 * @param request
    	 * @return
    	 */
    	public static String getClientIpAddress(HttpServletRequest request) {
    		String ip = request.getHeader("X-Forwarded-For");
    		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
    			ip = request.getHeader("X-Real-IP");
    		}
    		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
    			ip = request.getHeader("Cdn-Src-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.getRemoteAddr();
    		}
    		if (ip.indexOf(",") > -1) {
    			ip = ip.substring(0, ip.indexOf(","));
    		}
    		return ip;
    	}
    }
    

      

  • 相关阅读:
    eclipse中常用快捷键
    js sort排序
    js parseInt函数
    Jquery常用方法
    jquery的call()和apply()方法
    Jquery中的事件命名机制
    CSS层叠样式表
    推荐博客园中好的博客主
    页面刷新或者子窗体刷新父窗体,不提示 "重试或取消”对话框
    FullCalendar日历插件使用说明
  • 原文地址:https://www.cnblogs.com/jasonandy/p/9243332.html
Copyright © 2011-2022 走看看