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

推荐订阅源

Cloudbric
Cloudbric
E
Exploit-DB.com RSS Feed
SecWiki News
SecWiki News
Forbes - Security
Forbes - Security
N
News | PayPal Newsroom
S
Security @ Cisco Blogs
Schneier on Security
Schneier on Security
V
V2EX - 技术
S
Secure Thoughts
W
WeLiveSecurity
Google DeepMind News
Google DeepMind News
C
CERT Recently Published Vulnerability Notes
NISL@THU
NISL@THU
S
Securelist
S
Security Archives - TechRepublic
Know Your Adversary
Know Your Adversary
V
Vulnerabilities – Threatpost
Security Latest
Security Latest
Recent Commits to openclaw:main
Recent Commits to openclaw:main
G
GRAHAM CLULEY
H
Hacker News: Front Page
Microsoft Azure Blog
Microsoft Azure Blog
I
Intezer
Google Online Security Blog
Google Online Security Blog
美团技术团队
阮一峰的网络日志
阮一峰的网络日志
T
The Exploit Database - CXSecurity.com
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Webroot Blog
Webroot Blog
Jina AI
Jina AI
Engineering at Meta
Engineering at Meta
P
Proofpoint News Feed
The Cloudflare Blog
I
InfoQ
L
LangChain Blog
U
Unit 42
P
Proofpoint News Feed
S
Schneier on Security
S
Security Affairs
Y
Y Combinator Blog
T
Tenable Blog
N
News and Events Feed by Topic
MyScale Blog
MyScale Blog
量子位
Google DeepMind News
Google DeepMind News
Cyberwarzone
Cyberwarzone
博客园 - 聂微东
D
Darknet – Hacking Tools, Hacker News & Cyber Security
GbyAI
GbyAI
AWS News Blog
AWS News 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)  评论()    收藏  举报