通过代理访问URL

import java.io.*;
import java.net.*;
import java.util.*;
import java.util.regex.*;
public class AutoClick
{
public static int count = 0;
public static List ipList = new ArrayList();




public static void main(String[] args) throws Exception
{
String defurl="http://www.baidu.com";
// 从以下网址获得代理服务器ip列表
URL url = new URL("http://www.cemsg.com/proxy/");
if (Math.random() > 0.5)
{
url = new URL("http://www.cemsg.com/proxy/2.htm");
}
System.out.println("Use proxy list " + url);
URLConnection conn = url.openConnection();
BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String str = "";
StringBuffer sbuf = new StringBuffer();
while ((str = br.readLine()) != null)
{
sbuf.append(str);
}
str = sbuf.toString();
// 从HTML中筛出代理ip和port信息
Pattern p = Pattern.compile("\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}:\\d{2,4}");
Matcher m = p.matcher(str);
while (m.find())
{
ipList.add(str.substring(m.start(), m.end()));
}
// 开一个线程用随机的代理地址访问指定的url
new Thread(new ClickThread(defurl)).start();
}
}
class ClickThread implements Runnable
{
public ClickThread(String urlAddr) {
this.urlAddr = urlAddr;
}
String proxyIP;
String proxyPort;
String urlAddr;
public void run() {
while (true)
{
try
{
String[] ipInfos = AutoClick.ipList.get((int) (Math.random() * AutoClick.ipList.size())).toString().split(":");
System.setProperty("http.proxyHost", ipInfos[0]);
System.setProperty("http.proxyPort", ipInfos[1]);
URL url = new URL(urlAddr);
URLConnection conn = url.openConnection();
BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
int rc = 0;
while (br.readLine() != null)
{
rc++;
}
System.out.println("read " + rc);
br.close();
AutoClick.count++;
System.out.println(ipInfos[0] + ":" + ipInfos[1] + " click " + urlAddr + " " + AutoClick.count + " times");
}
catch (Exception e)
{
}
try
{
Thread.sleep(100);
}
catch (Exception e)
{
}
}
}
}

更多精彩:http://www.hxiaseo.cn
ext打包视频
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值