/**
此系统是模拟点击用户投放的广告,让用户所投放的网站广告提高点击率,难点是点击用户的广告需要加载比如站长工具之类的js统计代码,而且每个点击的ip不能相同,也就是要使用代理ip来实现点击,点击的REFERER必须是广告所投放的网站地址. 实现方式:java程序每准备点击一个广告,都修改注册表,从而达到修改浏览器代理服务器的地址.修改完成后启动一个浏览器来就行访问打开用户的广告地址,让浏览器来加载js统计代码.至于REFERER的实现是:在本地IIS配置一个站点,这个站点的主机名和网站投放地址的主机名一致
*/
adclicks.properties里面的内容,点击所需要读取的配置文件
proxy.reg里面的内容,修改浏览器代理ip地址的注册表文件,然后用java执行dos命令即可:regedit /s Path+proxy.reg
package ad;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import org.apache.log4j.Logger;
import proxyip.ProxyIp;
import ad.bean.Ad;
public class AdSystem {
final static Logger log = Logger.getLogger(AdSystem.class);
private static ExecutorService exec = Executors.newCachedThreadPool();
public static void main(String[] args) {
exec();
//监视,关闭浏览器
Thread t = new Thread(
new Runnable(){
public void run() {
int se = 20;
while(se > 0){
try {
System.out.println("----关闭浏览器倒计时"+se+"秒!");
TimeUnit.SECONDS.sleep(1);
se -- ;
if(se == 0){
Runtime.getRuntime().exec("taskkill /f /im iexplore.exe");
se=20;
}
} catch (Exception e) {e.printStackTrace();}
}
}
}
);
t.setDaemon(true);//不清楚线程池有没有setDaemon的相关方法,就使用这种方式
t.start();
}
public static void exec(){
List list = AdSource.getListAd();
for(final Ad ad : list){
Runnable command = new Runnable(){
public void run() {
System.out.println(ad.getPropkey()+"总执行时间:"+ad.getSecond()+"秒!");
System.out.println(ad.getPropkey()+"总点击次数:"+ad.getClicknum());
System.out.println(ad.getPropkey()+"时间间隔片段:"+ad.getListSec());
log.info(ad.getPropkey()+"总执行时间:"+ad.getSecond()+"秒!");
log.info(ad.getPropkey()+"总点击次数:"+ad.getClicknum());
log.info(ad.getPropkey()+"总执行时间:"+ad.getSecond()+"秒!");
LinkedList listSec = ad.getListSec();
ProxyIp proxy = new ProxyIp();
click(proxy);
while(listSec!=null && listSec.size()>0){
int nextSecond = listSec.pollFirst();
log.info(ad.getPropkey()+"总点击次数:"+ad.getClicknum()+"#当前次数:"+(ad.getClicknum()-listSec.size()));
System.out.println(ad.getPropkey()+"执行完成,下一次执行是在"+nextSecond+"秒之后");
try {
printSecond(nextSecond);
TimeUnit.SECONDS.sleep(nextSecond);
} catch (InterruptedException e) {e.printStackTrace();}
click(proxy);
}
}
//点击
public void click(ProxyIp proxy){
try {
System.out.println(ad.getPropkey()+"点击广告页面:"+ad.getAdurl());
proxy.updateBrowserProxy(ad);//修改浏览器的代理ip
Runtime.getRuntime().exec(AdSource.IELOCATION+" " +AdSource.IEJSPURL+"?adurl="+URLEncoder.encode(ad.getAdurl(),"utf-8"));
} catch (IOException e) {
e.printStackTrace();
}
}
//倒计时
public void printSecond(final int second){
exec.execute(new Runnable(){
public void run() {
int se = second;
while(se > 0){
try {
System.out.println(ad.getPropkey()+"倒计时"+se+"秒!");
TimeUnit.SECONDS.sleep(1);
} catch (InterruptedException e) {e.printStackTrace();}
se -- ;
}
}});
}
};
exec.execute(command);
}
}
}
package ad;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Properties;
import java.util.Random;
import java.util.Map.Entry;
import ad.bean.Ad;
/**
* 对adclikcs.properties文件里面的内容进行操作
* 得到配置文件里面的信息存入List
*/
public class AdSource {
static Properties prop = new Properties();
static String IELOCATION="";
static String IEJSPURL="";
static InputStream is = AdSource.class.getClassLoader().getResourceAsStream("adclicks.properties");
static{
try {
prop.load(is);
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
// System.out.println(getListAd());
float hour = 0.02f;
int second = (int)(hour*60*60);
System.out.println(second);
}
public static List getListAd(){
List list = new ArrayList();
for(Entry
package proxyip;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import ad.bean.Ad;
import ad.util.ProxyUtil;
public class ProxyIp {
private static String Path = ProxyIp.class.getClassLoader().getResource("proxyip").getPath();
public static void main(String[] args) {
System.out.println(Path);
ProxyIp proxy = new ProxyIp();
// proxy.updateBrowserProxy();
}
static StringBuilder sbproxy = new StringBuilder();
static{
sbproxy.append("REGEDIT4\r\n");
sbproxy.append("[HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings] \"ProxyEnable\"=dword:00000001\r\n");
sbproxy.append("\"ProxyServer\"=\"1.1.1.1:8080\"\r\n");
sbproxy.append("\"ProxyOverride\"=\"192.168.*;www.webname.cn\"\r\n");
}
//修改浏览器的代理
public void updateBrowserProxy(Ad ad){
try {
if(Path.startsWith("/")){
Path = Path.substring(1);
}
updateProxyReg(ad);
Runtime.getRuntime().exec("regedit /s "+Path+"/proxy.reg");
} catch (IOException e) {
e.printStackTrace();
}
}
//修改注册表文件
private static Lock lock = new ReentrantLock();
public void updateProxyReg(Ad ad){
lock.lock();
String proxyip = getProxyObj();
System.out.println("使用代理ip:"+proxyip);
String proxystr = sbproxy.toString();
proxystr = proxystr.replace("1.1.1.1:8080", proxyip);
proxystr = proxystr.replace("www.webname.cn", ad.getSourceurl().replace("http://", ""));
File file = new File(Path+"/proxy.reg");
FileWriter fw = null;
BufferedWriter bw = null;
try{
fw = new FileWriter(file);
bw = new BufferedWriter(fw);
bw.write(proxystr);
}catch(IOException e){
e.printStackTrace();
}finally{
try {
bw.close();
fw.close();
lock.unlock();
} catch (IOException e) {
e.printStackTrace();
}
}
}
/**
* 获取代理地址和端口号
*/
private List lists = ProxyUtil.getProxys();
private int index = 0;
public String getProxyObj(){
String p[] = {"",""};
boolean isproxy = true;
while(true){//获取代理地址和端口号
String proxy = lists.get(index++%(lists.size()-1));
if(proxy==null || proxy.equals("") || proxy.indexOf(":")==-1){
isproxy = false;
}else{
p = proxy.split(":");
if(Integer.parseInt(p[1])>65535)isproxy=false;
}
if(isproxy){
return proxy;
}
}
}
}
package ad.bean;
import java.util.LinkedList;
public class Ad {
private String sourceurl;//广告投放的网址
private String adurl;//广告链接地址
private Integer clicknum;//最少的次数
private float hour;//在多少个小时内完成点击,默认是24个小时
private int second;//在多少个小时内完成点击,默认是24个小时,进行转化为秒
private LinkedList listSec;//用于存放时间片段,在second时间内经过clicknum次分割得到的集合
private String propkey;
public String getSourceurl() {
return sourceurl;
}
public void setSourceurl(String sourceurl) {
this.sourceurl = sourceurl;
}
public String getAdurl() {
return adurl;
}
public void setAdurl(String adurl) {
this.adurl = adurl;
}
@Override
public String toString(){
return sourceurl+"#"+adurl+"#"+clicknum+"#"+hour;
}
public Integer getClicknum() {
return clicknum;
}
public void setClicknum(Integer clicknum) {
this.clicknum = clicknum;
}
public int getSecond() {
return second;
}
public void setSecond(int second) {
this.second = second;
}
public float getHour() {
return hour;
}
public void setHour(float hour) {
this.hour = hour;
}
public LinkedList getListSec() {
return listSec;
}
public void setListSec(LinkedList listSec) {
this.listSec = listSec;
}
public String getPropkey() {
return propkey;
}
public void setPropkey(String propkey) {
this.propkey = propkey;
}
}