博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
java代理ip有效检测
阅读量:6583 次
发布时间:2019-06-24

本文共 2662 字,大约阅读时间需要 8 分钟。

java实现代理ip有效检测,依赖Apache的HttpClient
 
正式版:

      
/**
       * 批量代理IP有效检测
       *
       * 
@param 
proxyIpMap
       * 
@param 
reqUrl
       */
      
public 
static 
void 
checkProxyIp(Map<String, Integer> proxyIpMap, String reqUrl) {
 
            
for 
(String proxyHost : proxyIpMap.keySet()) {
                  Integer proxyPort = proxyIpMap.get(proxyHost);
 
                  
int 
statusCode = 0;
                  
try 
{
                        HttpClient httpClient = 
new 
HttpClient();
                        httpClient.getHostConfiguration().setProxy(proxyHost, proxyPort);
 
                        
// 连接超时时间(默认10秒 10000ms) 单位毫秒(ms
                        
int 
connectionTimeout = 10000;
                        
// 读取数据超时时间(默认30秒 30000ms) 单位毫秒(ms
                        
int 
soTimeout = 30000;
                        httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(connectionTimeout);
                        httpClient.getHttpConnectionManager().getParams().setSoTimeout(soTimeout);
 
                        HttpMethod method = 
new 
GetMethod(reqUrl);
 
                        statusCode = httpClient.executeMethod(method);
                  } 
catch 
(Exception e) {
                        
// 
TODO 
Auto-generated catch block
                        e.printStackTrace();
                  }
                  System.
out
.format(
"%s:%s-->%s\n"
, proxyHost, proxyPort, statusCode);
            }
      }
 
      
/**
       * 代理IP有效检测
       *
       * 
@param 
proxyIp
       * 
@param 
proxyPort
       * 
@param 
reqUrl
       */
      
public 
static 
void 
checkProxyIp(String proxyIp, 
int 
proxyPort, String reqUrl) {
            Map<String, Integer> proxyIpMap = 
new 
HashMap<String, Integer>();
            proxyIpMap.put(proxyIp, proxyPort);
            checkProxyIp(proxyIpMap, reqUrl);
      }
      
      
public 
static 
void 
main(String[] args) {
            
            Map<String, Integer> proxyIpMap = 
new 
HashMap<String, Integer>();
            proxyIpMap.put(
"114.80.136.112"
, 7780);
            proxyIpMap.put(
"114.80.136.166"
, 7780);
            proxyIpMap.put(
"114.80.136.167"
, 7780);
            proxyIpMap.put(
"114.80.136.168"
, 7780);
            proxyIpMap.put(
"114.80.136.169"
, 7780);
            proxyIpMap.put(
"114.80.136.170"
, 7780);
            proxyIpMap.put(
"114.80.136.171"
, 7780);
            proxyIpMap.put(
"123.129.207.102"
, 7780);
            proxyIpMap.put(
"123.129.207.100"
, 7780);
            proxyIpMap.put(
"123.129.207.103"
, 7780);
            proxyIpMap.put(
"123.129.207.104"
, 7780);
            proxyIpMap.put(
"123.129.207.105"
, 7780);
            proxyIpMap.put(
"123.129.207.108"
, 7780);
            proxyIpMap.put(
"114.80.136.164"
, 7780);
            proxyIpMap.put(
"123.129.207.107"
, 7780);
            proxyIpMap.put(
"180.153.251.3"
, 7780);
            proxyIpMap.put(
"180.153.251.4"
, 7780);
            proxyIpMap.put(
"180.153.251.5"
, 7780);
            proxyIpMap.put(
"180.153.251.6"
, 7780);
            proxyIpMap.put(
"180.153.251.7"
, 7780);
            proxyIpMap.put(
"180.153.251.8"
, 7780);
            proxyIpMap.put(
"180.153.251.9"
, 7780);
            proxyIpMap.put(
"180.153.251.10"
, 7780);
            proxyIpMap.put(
"180.153.251.11"
, 7780);
            proxyIpMap.put(
"180.153.251.12"
, 7780);
            proxyIpMap.put(
"180.153.251.13"
, 7780);
            proxyIpMap.put(
"180.153.251.14"
, 7780);
            proxyIpMap.put(
"180.153.251.15"
, 7780);
            proxyIpMap.put(
"180.153.251.16"
, 7780);
            proxyIpMap.put(
"180.153.251.2"
, 7780);
            checkProxyIp(proxyIpMap, 
"http://t.sohu.com/new_index"
);
 
      }
 

转载地址:http://dfxno.baihongyu.com/

你可能感兴趣的文章
css中visiblity和display异同
查看>>
E - A strange lift 【数值型BFS+上下方向】
查看>>
最小生成树-prim算法模板
查看>>
京东笔试
查看>>
前端效果,前端框架,前端样式
查看>>
设计模式(十二)责任链模式
查看>>
关于asp.net core部署到iis中出现 HTTP Error 502.5 - Process Failure的问题
查看>>
go 内存优化
查看>>
[TopCoder] SRM 578 DIV 2, Goose In Zoo, Solution
查看>>
plink:将bed文件转化为ped,map文件
查看>>
单源最短路径Dijkstra算法,多源最短路径Floyd算法
查看>>
Hadoop学习之旅二:HDFS
查看>>
OSG3.0.1的编译
查看>>
【NET CORE微服务一条龙应用】应用部署
查看>>
Python数字
查看>>
VC调用ACM音频编程接口压缩Wave音频
查看>>
【原文转载】VIM复制粘贴大全
查看>>
鼠标移到一个图片上 图片放大
查看>>
PostgreSQL操作JSON数据
查看>>
execute sp_executesql 用变量获取返回值
查看>>