爬虫基于ADSL动态获取ip

爬虫访问中,如何解决网站限制IP的问题?    
 

开发了一个爬虫,布置在自己的服务器上,请求某网站的查询功能,然后抓取查询结果,结果访问才一会儿,就被提示封IP了。有什么好的解决方法吗? 

1. 某宝买代理,简单,但是太贵;

2. ADSL动态获取ip。


java代码:

  1. package com.sesame.network;  
  2.   
  3. import java.io.BufferedReader;  
  4. import java.io.InputStreamReader;  
  5.   
  6. public class ConnectNetWork {  
  7.   
  8.     /** 
  9.      * 执行CMD命令,并返回String字符串 
  10.      */  
  11.     public static String executeCmd(String strCmd) throws Exception {  
  12.         Process p = Runtime.getRuntime().exec("cmd /c " + strCmd);  
  13.         StringBuilder sbCmd = new StringBuilder();  
  14.         BufferedReader br = new BufferedReader(new InputStreamReader(p  
  15.                 .getInputStream()));  
  16.         String line;  
  17.         while ((line = br.readLine()) != null) {  
  18.             sbCmd.append(line + "\n");  
  19.         }  
  20.         return sbCmd.toString();  
  21.     }  
  22.   
  23.     /** 
  24.      * 连接ADSL 
  25.      */  
  26.     public static boolean connAdsl(String adslTitle, String adslName, String adslPass) throws Exception {  
  27.         System.out.println("正在建立连接.");  
  28.         String adslCmd = "rasdial " + adslTitle + " " + adslName + " "  
  29.                 + adslPass;  
  30.         String tempCmd = executeCmd(adslCmd);  
  31.         // 判断是否连接成功  
  32.         if (tempCmd.indexOf("已连接") > 0) {  
  33.             System.out.println("已成功建立连接.");  
  34.             return true;  
  35.         } else {  
  36.             System.err.println(tempCmd);  
  37.             System.err.println("建立连接失败");  
  38.             return false;  
  39.         }  
  40.     }  
  41.   
  42.     /** 
  43.      * 断开ADSL 
  44.      */  
  45.     public static boolean cutAdsl(String adslTitle) throws Exception {  
  46.         String cutAdsl = "rasdial " + adslTitle + " /disconnect";  
  47.         String result = executeCmd(cutAdsl);  
  48.          
  49.         if (result.indexOf("没有连接")!=-1){  
  50.             System.err.println(adslTitle + "连接不存在!");  
  51.             return false;  
  52.         } else {  
  53.             System.out.println("连接已断开");  
  54.             return true;  
  55.         }  
  56.     }  
  57.      
  58.     public static void main(String[] args) throws Exception {  
  59.         connAdsl("宽带","hzhz**********","******");  
  60.         Thread.sleep(1000);  
  61.         cutAdsl("宽带");  
  62.         Thread.sleep(1000);  
  63.         //再连,分配一个新的IP  
  64.         connAdsl("宽带","hzhz**********","******");  
  65.     }  
  66. }  

 


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Soyoger

听说打赏的都进了福布斯排行榜。

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值