java获取当前网络IP地址
2022/1/8 17:06:38
本文主要是介绍java获取当前网络IP地址,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
1 /** 2 * 获取当前网络ip 3 * 4 * @param request 5 * @return 6 */ 7 @RequestMapping("getIpAddress") 8 public static String getIpAddress(HttpServletRequest request) { 9 String ip = request.getHeader("x-forwarded-for"); 10 if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 11 ip = request.getHeader("Proxy-Client-IP"); 12 } 13 if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 14 ip = request.getHeader("WL-Proxy-Client-IP"); 15 } 16 if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 17 ip = request.getHeader("HTTP_CLIENT_IP"); 18 } 19 if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 20 ip = request.getHeader("HTTP_X_FORWARDED_FOR"); 21 } 22 if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 23 ip = request.getRemoteAddr(); 24 } 25 return ip; 26 }
这篇关于java获取当前网络IP地址的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-12-25初学者必备:订单系统资料详解与实操教程
- 2024-12-24内网穿透资料入门教程
- 2024-12-24微服务资料入门指南
- 2024-12-24微信支付系统资料入门教程
- 2024-12-24微信支付资料详解:新手入门指南
- 2024-12-24Hbase资料:新手入门教程
- 2024-12-24Java部署资料
- 2024-12-24Java订单系统资料:新手入门教程
- 2024-12-24Java分布式资料入门教程
- 2024-12-24Java监控系统资料详解与入门教程