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打包视频