/** * @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; }
总结以上是内存溢出为你收集整理的java获取本机ip地址(写出来的)全部内容,希望文章能够帮你解决java获取本机ip地址(写出来的)所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)