当前位置:网站首页>Get the Ip tool class
Get the Ip tool class
2022-08-03 04:40:00 【Dzooooone_】
public class IPUtil {public static String getIpAddress(HttpServletRequest request) {String ipAddress = request.getHeader("x-forwarded-for");if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {ipAddress = request.getHeader("Proxy-Client-IP");}if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {ipAddress = request.getHeader("WL-Proxy-Client-IP");}if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {ipAddress = request.getRemoteAddr();if (ipAddress.equals("127.0.0.1") || ipAddress.equals("0:0:0:0:0:0:0:1")) {// Get the IP configured by the machine according to the network cardInetAddress inet = null;try {inet = InetAddress.getLocalHost();} catch (UnknownHostException e) {e.printStackTrace();}ipAddress = inet.getHostAddress();}}// For the case of passing through multiple proxies, the first IP is the real IP of the client, and multiple IPs are divided according to ','if (ipAddress != null && ipAddress.length() > 15) { // "***.***.***.***".length() = 15if (ipAddress.indexOf(",") > 0) {ipAddress = ipAddress.substring(0, ipAddress.indexOf(","));}}return ipAddress;}}
边栏推荐
猜你喜欢
随机推荐
flink sql任务变更,在sql里面增加几个字段后,从以前保存的savepoint恢复启动出错。
Interface test practice | Detailed explanation of the difference between GET / POST requests
Test drive: project management module - curd development project
Flink状态
[Developers must see] [push kit] Collection of typical problems of push service service 2
浏览器监听标签页关闭
2022 Henan Mengxin League Game (4): Zhengzhou University of Light Industry E - Sleep Well
三丁基-巯基膦烷「tBuBrettPhos Pd(allyl)」OTf),1798782-17-8
接口和协议
MOSN 反向通道详解
Interface test framework combat (1) | Requests and interface request construction
私域流量时代来临,电商企业如何布局?
How to prepare for the test interface test data
【Harmony OS】【ArkUI】ets开发 图形与动画绘制
修饰生物素DIAZO-生物素-PEG3-DBCO|重氮-生物素-三聚乙二醇-二苯基环辛炔
Oracle EMCC可以独立安装吗?还是必须安装到数据库服务器上?
中断系统需要解决的问题
数据库基本概述与SQL概述
用户密码验证
RequestContextHolder