public class IpUtils{ /** * 获取ip地址 * @param request * @return */ public static String getIpAddr(HttpServletRequest request) { String ip = request.getHeader("x-forwarded-for"); if (ip != null && !ip.isEmpty()) { ip = ip.split(",")[0].trim(); } 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(); } return ip; } }
根据ip获取地理位置/天气信息等:
http://www.jb51.net/article/54287.htm
http://blog.csdn.net/wssiqi/article/details/8550951
时间: 2024-10-27 18:17:28