Http 通过setHeader隐藏ip
**
HttpGet httpGet=new HttpGet(“http://localhost/”);
通过 httpGet.setHeader(“x-forwarded-for”,“123456”);来隐藏ip。
为什么能达到隐藏ip效果,现在我们来看看GetRemoteAddr的底层实现
String ipString = request.getHeader("x-forwarded-for");
if (StringUtils.isBlank(ipString) || "unknown".equalsIgnoreCase(ipString)) {
ipString = request.getHeader("Proxy-Client-IP");
}
if (StringUtils.isBlank(ipString) || "unknown".equalsIgnoreCase(ipString)) {
ipString = request.getHeader("WL-Proxy-Client-IP");
}
if (StringUtils.isBlank(ipString) || "unknown".equalsIgnoreCase(ipString)) {
ipString = request.getRemoteAddr();
}
request.getRemoteAddr()
咳咳
我们可以看到它是通过request.getHeader(“x-forwarded-for”)来获取ip,
那么我们只需要再发送http请求时.SetHeader(“x-forwarded-for”,ip)即可
达到隐藏ip的目的