当前位置:网站首页>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;}}
边栏推荐
- 【开发者必看】【push kit】推送服务服务典型问题合集2
- Windows 安装PostgreSQL
- DFS's complement to pruning
- 接口测试框架实战(三)| JSON 请求与响应断言
- 记录一些遇见的bug——mapstruct和lombok同时使用时,转换实体类时数据丢失问题
- Can Oracle EMCC be installed independently?Or does it have to be installed on the database server?
- Kotlin-Flow常用封装类:StateFlow的使用
- 7.Keras开发简介
- GIS数据漫谈(五)— 地理坐标系统
- Concepts and Methods of Exploratory Testing
猜你喜欢
我将GuiLite移植到了STM32F4开发板上
2022/08/02 Study Notes (day22) Multithreading
GIS数据漫谈(六)— 投影坐标系统
Interface Test Framework Practice (4) | Get Schema Assertion
How to use the interface management tool YApi?Beautiful, easy to manage, super easy to use
v-text指令:设置标签内容
【Harmony OS】【FAQ】Hongmeng Questions Collection 1
接口管理工具YApi怎么用?颜值高、易管理、超好用
MOSN 反向通道详解
Harmony OS ets ArkUI 】 【 】 the development basic page layout and data connection
随机推荐
unity2D横板游戏教程6-敌人AI以及受击动画
OpenFOAM extracts equivalency and calculates area
中断系统需要解决的问题
mysql 创建索引的三种方式
Redis连接不上的报错解决方案汇总
安装ambari
好消息!北京、珠海PMP考试时间来啦
DDL操作数据库、表、列
Browser listens for tab closing
Two ways to simulate multi-user login in Jmeter
Super handy drawing tool is recommended
mysql bool盲注
Jmeter 模拟多用户登录的两种方法
接口测试框架实战(二)| 接口请求断言
修饰生物素DIAZO-生物素-PEG3-DBCO|重氮-生物素-三聚乙二醇-二苯基环辛炔
2.何为张量
【Harmony OS】【ARK UI】ETS 上下文基本操作
用户密码验证
社交电商:链动2+1模式,为什么能在电商行业生存那么久?
How to use the interface management tool YApi?Beautiful, easy to manage, super easy to use