//获取请求客户端IP地址     

public final static String getIpAddress(HttpServletRequest request) throws IOException {  
         // 获取请求主机IP地址,如果通过代理进来,则透过防火墙获取真实IP地址  
         String ip = request.getHeader("X-Forwarded-For");  
         if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {  
             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.getHeader("HTTP_CLIENT_IP");  
             }  
             if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {  
                 ip = request.getHeader("HTTP_X_FORWARDED_FOR");  
             }  
             if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {  
                 ip = request.getRemoteAddr();  
             }  
         } else if (ip.length() > 15) {  
             String[] ips = ip.split(",");  
             for (int index = 0; index < ips.length; index++) {  
                 String strIp = (String) ips[index];  
                 if (!("unknown".equalsIgnoreCase(strIp))) {  
                     ip = strIp;  
                     break;  
                 }  
             }  
         }  
         return ip;  
     }

     //指定伪IP地址代理请求
            String visitIP=getIpAddress(request);
            URL url = new URL("http://www.baidu.com");    
            URLConnection connection = url.openConnection();    
         
            connection.setRequestProperty("X-Forwarded-For",visitIP);
            connection.setRequestProperty("Proxy-Client-IP",visitIP);
            connection.setRequestProperty("WL-Proxy-Client-IP",visitIP);
            connection.setRequestProperty("HTTP_CLIENT_IP",visitIP);
            connection.setRequestProperty("HTTP_X_FORWARDED_FOR",visitIP);
            connection.setRequestProperty("REMOTE_ADDR",visitIP);
            connection.setRequestProperty("User-Agent","Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.142 Safari/535.19");
//            connection.setConnectTimeout(30000);
//            connection.setReadTimeout(30000);
            connection.connect();
            BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(),"UTF-8"));
            String line;    
            while((line = reader.readLine())!= null){     
                 result.append(line);    
            }
           System.out.prinlt(result.toString());

获取IP地址 & 伪装IP地址发送请求的更多相关文章

  1. [python网络编程]使用scapy修改源IP发送请求

    Python爬虫视频教程零基础小白到scrapy爬虫高手-轻松入门 https://item.taobao.com/item.htm?spm=a1z38n.10677092.0.0.482434a6E ...

  2. 爬虫模块介绍--request(发送请求模块)

    爬虫:可见即可爬   # 每个网站都有爬虫协议 基础爬虫需要使用到的三个模块 requests 模块  # 模拟发请求的模块 PS:python原来有两个模块urllib和urllib的升级urlli ...

  3. webapi获取请求地址的IP

    References required: HttpContextWrapper - System.Web.dll RemoteEndpointMessageProperty - System.Serv ...

  4. 获取请求地址的IP地址

    public static String getIpAddr(HttpServletRequest request) throws Exception { String ip = request.ge ...

  5. 获取客户端IP地址的三个HTTP请求头的区别

    一.没有使用代理服务器的情况: REMOTE_ADDR = 您的 IP HTTP_VIA = 没数值或不显示 HTTP_X_FORWARDED_FOR = 没数值或不显示 二.使用透明代理服务器的情况 ...

  6. JAVA获取客户端IP地址和MAC地址

    1.获取客户端IP地址 public String getIp(HttpServletRequest request) throws Exception { String ip = request.g ...

  7. C#获取路由器外网IP,MAC地址

    C#实现的获取路由器MAC地址,路由器外网地址.对于要获取路由器MAC地址,一定需要知道路由器web管理系统的用户名和密码.至于获取路由器的外网IP地址,可以不需要知道路由器web管理系统的用户名和密 ...

  8. ASP.NET获取真正的客户端IP地址的6种方法

    Request.ServerVariables("REMOTE_ADDR") 来取得客户端的IP地址,但如果客户端是使用代理服务器来访问,那取到的就是代理服务器的IP地址,而不是真 ...

  9. Java里面获取当前服务器的IP地址

    public static void main(String[] args) { try { InetAddress address = InetAddress.getLocalHost();//获取 ...

随机推荐

  1. Python之路,Day7 - Python基础7 面向对象

    本节内容:   面向对象编程介绍 为什么要用面向对象进行开发? 面向对象的特性:封装.继承.多态 类.方法.     引子 你现在是一家游戏公司的开发人员,现在需要你开发一款叫做<人狗大战> ...

  2. angular-route 和soket注意细节点

    route run 文件是第一个位置,之后才配置路由哪些,代码: angular.module('technodeApp',['ngRoute']).run(function($window,$roo ...

  3. wget 扒站

    在Linux下,通过一个命令就可以把整个站相关的文件全部下载下来. wget -r -p -k -np [网址] 参数说明: -r : 递归下载 -p : 下载所有用于显示 HTML 页面的图片之类的 ...

  4. PEtools

    // PETools.cpp : Defines the entry point for the console application.// #include "stdafx.h" ...

  5. Ruby数组

    Ruby数组是有序的,任何对象的整数索引的集合.每个数组中的元素相关联,并提取到的一个索引.下标与C或Java相似,从0开始.负数索引假设数组末尾,也就是说-1表示最后一个元素的数组索引,-2是数组中 ...

  6. Idea 快捷键

    Ctrl+Alt+T 选中代码块加try catch等常用快捷操作.如图: psvm+Tab键 快速创建main方法 pout+Tab键 快速打出System.out.println(); Ctrl+ ...

  7. Scrapy 爬虫 使用指南 完全教程

    scrapy note command 全局命令: startproject :在 project_name 文件夹下创建一个名为 project_name 的Scrapy项目. scrapy sta ...

  8. 安装opensuse时遇到的一些问题

    1.硬盘安装suse的时候提示找不到源,因为是2块硬盘所以需要mount一下硬盘. 2.安装N卡驱动的时候,推荐一键安装,不然需要把所有GCC和make安装好,并且禁用系统的nouneau.

  9. resin实现热部署配置

    修改resin.xml文件 <host id="test.com" root-directory="."> <host-alias>te ...

  10. 微信开发笔记:获取用户openid,以及用户头像昵称等信息

    微信开发的时候有一个很便利的途径来进行一个用户的一步注册登录,就是使用用户的微信信息来直接进行登陆,可以省去很多不必要的麻烦.那具体这些信息是如何来获取的呢? 首先呢,我们需要对微信进行一个授权,让微 ...