java里,怎么取得IP地址
IP地址是114.241.37.152内网IP是192.168.1.100这个IP放我我的网站,jsp的网站怎么取得这两个IP...
IP地址是114.241.37.152
内网IP是192.168.1.100
这个IP放我我的网站,jsp的网站
怎么取得这两个IP 展开
内网IP是192.168.1.100
这个IP放我我的网站,jsp的网站
怎么取得这两个IP 展开
1个回答
展开全部
package A;
import javax.servlet.http.HttpServletRequest;
public class a {
public String getRemortIP(HttpServletRequest request)
{
if (request.getHeader("x-forwarded-for") == null)
{
return request.getRemoteAddr();
}
return request.getHeader("x-forwarded-for");
}
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;
}
}
接着有些了个jsp来调用:
<%@ page language="java" import="java.util.*,A.*" pageEncoding="utf-8"%>
<jsp:useBean id="test" class="A.a" scope="request" > </jsp:useBean>
<%
out.println("request.getRemoteAddr(): " + request.getRemoteAddr()); //这里输出的不是真正的ip
test.getIpAddr(); //这里的参数怎么写?
%>
import javax.servlet.http.HttpServletRequest;
public class a {
public String getRemortIP(HttpServletRequest request)
{
if (request.getHeader("x-forwarded-for") == null)
{
return request.getRemoteAddr();
}
return request.getHeader("x-forwarded-for");
}
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;
}
}
接着有些了个jsp来调用:
<%@ page language="java" import="java.util.*,A.*" pageEncoding="utf-8"%>
<jsp:useBean id="test" class="A.a" scope="request" > </jsp:useBean>
<%
out.println("request.getRemoteAddr(): " + request.getRemoteAddr()); //这里输出的不是真正的ip
test.getIpAddr(); //这里的参数怎么写?
%>
Storm代理
2023-07-25 广告
2023-07-25 广告
StormProxies是一家提供动态代理服务器服务的企业,旨在帮助用户更好地管理网络访问和安全。以下是一些关于StormProxies的IP动态代理服务的特点:1. 高匿名性:StormProxies的动态代理服务器具有高匿名性,可以有效...
点击进入详情页
本回答由Storm代理提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询