您的位置:首页 > 其它

手把手教你写灌水机器,全智能自己定,,想怎么灌就怎么灌~

2006-05-24 17:51 501 查看
慎重申明:
仅供学习研究之用,不可做不该做的事~~保留作者名义!!
这是我前些日子根据我学校的BBS写的灌水程序,现在帖到自己的BLOG请根据你要实验的BBS提交表单作相应改动.

22:42 2006-4-22
我们使用开源HttpClient,该开源项目用来提供高效的、最新的、功能丰富的支持 HTTP 协议的客户端编程工具包,并且它支持 HTTP 协议最新的版本和建议。
我在以前那个公司做单元测试程序测试SERVLET代码和做压力测试程序测试系统压力时就是使用的它,它比JAVA里本有的net功能强而且容易使用。
因此,在这里我们还是使用它。
一 配置HttpClient
请把附件ext.rar解压放入JRE的库路径,比如:C:/Program Files/Java/j2re1.4.2_02/lib/ext。道理不用我说,当然是使得我们的程序可以使用这个开源包。
占位帖代码~~

package bbs;
//引入开源包
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.NameValuePair;

public class BbsUp {
public static void main(String[] args) {
HttpClient httpClient = new HttpClient();
String bbsNumberStr = args[0];//接收参数,以作为个人已经发帖子数
int bbsNumberInt = Integer.parseInt(bbsNumberStr);//从字符转换为整型
String loginUrl = "http://bbs.ctbu.edu.cn/login.php";//登陆url
String updateUrl = "http://bbs.ctbu.edu.cn/post.php";//发帖url
try{
//登陆
PostMethod postMethod=new PostMethod(loginUrl);

NameValuePair[] data = { new NameValuePair("pwuser", "你的BBS账号,比如我的就是lenky,则这儿就写lenky"),
new NameValuePair("pwpwd", "不用我说,当然是BBS账号密码"),
new NameValuePair("hideid", "0"),
new NameValuePair("jumpurl", "http://bbs.ctbu.edu.cn/"),
new NameValuePair("step", "2"),
new NameValuePair("cktime", "31536000"),
};
postMethod.setRequestBody(data);

int statusCode=httpClient.executeMethod(postMethod);
System.out.println(statusCode);

if(statusCode==HttpStatus.SC_MOVED_PERMANENTLY||statusCode==HttpStatus.SC_MOVED_TEMPORARILY){
Header locationHeader = postMethod.getResponseHeader("location");
String location = null;
if(locationHeader!=null){
location = locationHeader.getValue();
System.out.println("The page was redirected to:" + location);
}else{
System.err.println("Location field value is null.");
}
//return;
}
postMethod.releaseConnection();

//回帖
postMethod=new PostMethod(updateUrl);
boolean b=true;
while(b){//循环回帖
NameValuePair[] data1 = {new NameValuePair("atc_title", "Re:....."),
new NameValuePair("atc_content", "automatic reply program update! /n reply the topic every 40 second! /n number:" + (bbsNumberInt++) + " /n reply time:" + new java.util.Date()),
new NameValuePair("step", "2"),
new NameValuePair("action", "reply"),
new NameValuePair("fid", "16"),
new NameValuePair("tid", "127795"),
new NameValuePair("editor", "0"),
new NameValuePair("atc_attachment", "none"),
};
postMethod.setRequestBody(data1);

int statusCode1=httpClient.executeMethod(postMethod);
System.out.println(statusCode1);

if(statusCode==HttpStatus.SC_MOVED_PERMANENTLY||statusCode==HttpStatus.SC_MOVED_TEMPORARILY){
Header locationHeader = postMethod.getResponseHeader("location");
String location = null;
if(locationHeader!=null){
location = locationHeader.getValue();
System.out.println("The page was redirected to:" + location);
}else{
System.err.println("Location field value is null.");
}
//return;
}
Thread.sleep(1000*40);//等待40秒
System.out.println("number:" + bbsNumberInt);

}
postMethod.releaseConnection();

}catch(Exception err){
System.out.println(err.getMessage());
}finally{

}
}
}

上面就是全部代码,简单吧?

NameValuePair[] data = { new NameValuePair("pwuser", "你的BBS账号,比如我的就是lenky,则这儿就写lenky"),
new NameValuePair("pwpwd", "不用我说,当然是BBS账号密码"),
new NameValuePair("hideid", "0"),
new NameValuePair("jumpurl", "http://bbs.ctbu.edu.cn/"),
new NameValuePair("step", "2"),
new NameValuePair("cktime", "31536000"),
};

以上参数的来由请分析http://bbs.ctbu.edu.cn/login.php的html的表单代码。

new NameValuePair("atc_title", "Re:....."),
new NameValuePair("atc_content", "automatic reply program update! /n reply the topic every 40 second! /n number:" + (bbsNumberInt++) + " /n reply time:" + new java.util.Date()),
new NameValuePair("step", "2"),
new NameValuePair("action", "reply"),
new NameValuePair("fid", "16"),
new NameValuePair("tid", "127795"),
new NameValuePair("editor", "0"),
new NameValuePair("atc_attachment", "none"),

以上参数的来由:我对哪帖做自动回复就分析哪帖的页面
比如我就对本贴做自动回复程序就分析
http://bbs.ctbu.edu.cn/read.php?tid=127795
的表单代码。
分析多帖之后,你会发现一般只需改动fid(是指论坛ID,可能是forum id的简写)和tid(指帖子ID,可能是帖(tie id的简写)
智能改进
一方面,从回复内容着手,我们可以事先写好多条(比如150条)广泛适用的回复保存在文件(比如文本文件),开程序启动后把回复内容保存在数组(或其它比如map,list,set等).再在自动回复随机抽取一条进行回复.
另一方面,在程序里的new NameValuePair("fid", "16"),new NameValuePair("tid", "127795")值可以也取随机数(当然要研究下其规律,比如范围等),若是可以访问的页面(此时,状态码返回200),则随机回复一条信息.若是不可以访问的页面(此时,状态码返回比如404或其它或者页面里有提示信息比如页面里有"帖子ID非法"的提示等等),则再进行下次随机访问.

二.分析访问页面的内容,这就涉及比较深了,呵呵,
我原来也就只是分析下最上几楼的回复(比如楼主发帖的标题和内容,再就是前面几楼的回复),查找关键字,再进行简单的分析判断回复哪句比较好等.

原来我用C语言写过灌水程序,但是太麻烦了,后来代码也不知道哪儿去了.不过可以想象,比这麻烦多了.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐