获取电脑ip地址的代码工具类

获取ip地址的工具类

import javax.servlet.http.HttpServletRequest;  import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.util.StringUtils; import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes;  public class IPUtils { 	private static Logger logger = LoggerFactory.getLogger(IPUtils.class); 	public static String getIpAddr() { 		HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); 		String ip = null; 		try { 			ip = request.getHeader("x-forwarded-for"); 					if (StringUtils.isEmpty(ip) || "unknown".equalsIgnoreCase(ip)) { 						ip = request.getHeader("Proxy-Client-IP"); 					} 					if (StringUtils.isEmpty(ip) || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 						ip = request.getHeader("WL-Proxy-Client-IP"); 					} 					if (StringUtils.isEmpty(ip) || "unknown".equalsIgnoreCase(ip)) { 						ip = request.getHeader("HTTP_CLIENT_IP"); 					} 					if (StringUtils.isEmpty(ip) || "unknown".equalsIgnoreCase(ip)) { 						ip = request.getHeader("HTTP_X_FORWARDED_FOR"); 					} 					if (StringUtils.isEmpty(ip) || "unknown".equalsIgnoreCase(ip)) { 						ip = request.getRemoteAddr(); 					} 		} catch (Exception e) { 			logger.error("IPUtils ERROR ", e); 		} 		return ip; 	} }  

区块链毕设网(www.qklbishe.com)全网最靠谱的原创区块链毕设代做网站
部分资料来自网络,侵权联系删除!
资源收费仅为搬运整理打赏费用,用户自愿支付 !
qklbishe.com区块链毕设代做网专注|以太坊fabric-计算机|java|毕业设计|代做平台 » 获取电脑ip地址的代码工具类

提供最优质的资源集合

立即查看 了解详情