Jave 从 httpRequest 中获取 ip 地址
2015-12-24 18:42
435 查看
public String getIpAddr(HttpServletRequest request) {
String ip = request.getHeader("x-forwarded-for");
if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("Proxy-Client-IP");
}
if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("WL-Proxy-Client-IP");
}
if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getRemoteAddr();
}
return ip;
}
String ip = request.getHeader("x-forwarded-for");
if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("Proxy-Client-IP");
}
if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("WL-Proxy-Client-IP");
}
if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getRemoteAddr();
}
return ip;
}
相关文章推荐
- http响应状态码测试脚本(python版)
- 三步解决fiddler升级后https无法通过证书验证问题
- iOS检测网络是否断开
- linux 下 httpd 2.4 的编译安装
- 使用HttpClient远程抓取网页内容
- Apache 配置HTTPS协议搭载SSL配置
- TOMCAT HTTPS访问配置应用
- HTTP笔记(三)HTTP的method
- 网络共享
- HTTP协议
- 使用HttpURLConnection下载带空格或中文名字的文件时出现找不到
- WinInet, WinHttp, Winsock, ws2_32的基本解释
- nginx使用ssl模块配置HTTPS支持
- 关于IOS9 网络适配
- Android Volley入门到精通:使用Volley加载网络图片
- 【iCore3 双核心板】例程二十:LAN_TCPC实验——以太网数据传输
- HTTP请求常见错误大全
- iOS获取网络类型和运营商信息
- HTTP笔记(二)HTTP协议的通信
- 深入理解Linux网络技术内幕-设备注册和初始化(三)