当前位置:网站首页>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;}}
边栏推荐
猜你喜欢
Interface Test Framework Practice (4) | Get Schema Assertion
How to use the interface management tool YApi?Beautiful, easy to manage, super easy to use
Where is the value of testers
OpenFOAM提取等职面并计算面积
Redis缓存雪崩、缓存穿透、缓存击穿
CobalStrike(CS)基础超级详细版
探索性测试的概念及方法
Problems that need to be solved for interrupting the system
测试人员的价值体现在哪里
GIS数据漫谈(六)— 投影坐标系统
随机推荐
Shenzhen Offline Registration|StarRocks on AWS: How to conduct rapid and unified analysis of real-time data warehouses
9.新闻分类:多分类问题
CyberArk被评为2022年Gartner特权访问管理魔力象限领导者
Shell之条件语句
接口测试框架实战(二)| 接口请求断言
WebSocket的实际应用
How to prepare for the test interface test data
Flink状态
私域流量引流方法?分享购火爆的商业模式,你值得拥有
【Harmony OS】【ARK UI】ETS 上下文基本操作
Interface Test Framework Practice | Process Encapsulation and Test Case Design Based on Encrypted Interface
Interface testing framework combat (3) | JSON request and response assertion
社交电商:流量红利已尽,裂变营销是最低成本的获客之道
Record some bugs encountered - when mapstruct and lombok are used at the same time, the problem of data loss when converting entity classes
The flink sql task is changed, and after adding several fields to the sql, an error occurs when restoring from the previously saved savepoint.
Redis缓存雪崩、缓存穿透、缓存击穿
Live | StarRocks technology insider: low base dictionary global optimization
Jmeter 模拟多用户登录的两种方法
excerpt from compilation book
Test drive: project management module - curd development project