惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

I
InfoQ
B
Blog RSS Feed
Stack Overflow Blog
Stack Overflow Blog
WordPress大学
WordPress大学
小众软件
小众软件
GbyAI
GbyAI
Martin Fowler
Martin Fowler
Blog — PlanetScale
Blog — PlanetScale
爱范儿
爱范儿
D
DataBreaches.Net
大猫的无限游戏
大猫的无限游戏
T
Tailwind CSS Blog
Microsoft Security Blog
Microsoft Security Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
N
Netflix TechBlog - Medium
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
The GitHub Blog
The GitHub Blog
Google DeepMind News
Google DeepMind News
月光博客
月光博客
人人都是产品经理
人人都是产品经理
S
SegmentFault 最新的问题
H
Hackread – Cybersecurity News, Data Breaches, AI and More
G
Google Developers Blog
宝玉的分享
宝玉的分享

博客园 - 星朝

博客园搬家 窗口函数详细用法 JVM启动参数大全 BigDecimal.setScale用法总结 - 星朝 - 博客园 springboot项目上传文件出现临时文件目录为空 springboot中多线程中使用MultipartFile进行异步操作报错,系统找不到指定的文件 java获取本机IP Spring中的@Transactional(rollbackFor = Exception.class)属性详解 注解@CrossOrigin解决跨域问题 unique key index区别 mysql 创建唯一约束表 MySQL中添加唯一约束和联合唯一约束 移动IM开源框架Tigase > Openfire > Ejabberd对比分析 Tigase 8.0开发环境搭建 Tigase手动安装过程 几个时序数据库 时序数据库入门 MySQL执行计划extra中的using index 和 using where using index 的区别 ETL的详细解释定义
Java获取本机ip和服务器ip
星朝 · 2020-01-14 · via 博客园 - 星朝

一、获取服务器IP

 1 String addr = InetAddress.getLocalHost().getHostAddress();//获得本机IP  

二、获取客户端本机IP

复制代码

复制代码

 1 String remoteAddr = request.getRemoteAddr();  
 2 String forwarded = request.getHeader("X-Forwarded-For");  
 3 String realIp = request.getHeader("X-Real-IP");  
 4 String ip = null;  
 5 if (realIp == null) {  
 6     if (forwarded == null) {  
 7         ip = remoteAddr;  
 8     } else {  
 9         ip = remoteAddr + "/" + forwarded.split(",")[0];  
10     }  
11 } else {  
12     if (realIp.equals(forwarded)) {  
13         ip = realIp;  
14     } else {  
15         if(forwarded != null){  
16             forwarded = forwarded.split(",")[0];  
17         }  
18         ip = realIp + "/" + forwarded;  
19     }  
20 }  

复制代码

posted @ 2020-01-14 16:43  星朝  阅读(2445)  评论()    收藏  举报