一個朋友寫的新浪灌水機一部
//灌水開始了
using System;
using System.IO;
using System.Net; using System.Collections.Specialized;
using System.Text;
namespace sina1
{
///
/// Summary description for Class1.
///
class Class1
{
///
/// The main entry point for the application.
///
[STAThread]
static void Main(string[] args)
{
// test3();
// return;
//
// test1();
// return;
WebClient clubIndexRequest = new WebClient();
clubIndexRequest.Headers.Add("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT
5.1; .NET CLR 1.1.4322)");
clubIndexRequest.Headers.Add("Accept", "*/*)");
Stream stream = clubIndexRequest.OpenRead("http://house.sina.com.cn/allclub/index.html");
StreamReader reader = new StreamReader(stream);
String clubIndexResponse = reader.ReadToEnd();
String url = "href=http://comment.sina.com.cn/cgi-bin/comment/comment.cgi";
int pos1 = 0;
int pos2 = 0;
String userName = System.Web.HttpUtility.UrlEncode("抗議松下熱水器",
Encoding.GetEncoding("GB2312"));
string rawContent = "恐怖的鬆_下熱水器/r/n我本來不想買小_日本的東西的,但是老婆做主,買了
一個鬆_下的燃氣熱水器,花了1千8百多大洋/r/n沒想到安裝的時候還收了我522元,522元啊!/r/n今天
打投訴電話,居然說還有收8百多的!/r/n各位業主,買鬆_下熱水器的時候小心啊,說不定象我這樣當了
冤大頭。/r/n我可以提供證據。";
String content = System.Web.HttpUtility.UrlEncode(rawContent, Encoding.GetEncoding
("GB2312"));
while((pos1 = clubIndexResponse.IndexOf(url, pos2)) >= 0)
{
// 分析業主論壇
pos1 += url.Length + 1;
pos2 = clubIndexResponse.IndexOf(" ", pos1);
String clubStr = clubIndexResponse.Substring(pos1, pos2 - pos1);
// 預提交(新浪的防灌水措施)
// 創建post數據
String postStr = clubStr;
postStr = postStr + "&top_title=";
postStr = postStr + "&top_url=";
postStr = postStr + "&user=" + userName;
postStr = postStr + "&password=" + password;
postStr = postStr + "&content=" + content;
postStr = postStr + "&temp_content=" + content;
byte [] postData = Encoding.ASCII.GetBytes(postStr);
WebClient command = new WebClient();
command.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
command.Headers.Add("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;
.NET CLR 1.1.4322)");
command.Headers.Add("Accept", "*/*)");
try
{
byte [] returnData = command.UploadData("http://comment.sina.com.cn/cgi-
bin/comment/comment_do.cgi", "POST", postData);
String cookie = command.ResponseHeaders["Set-Cookie"];
String returnStr = Encoding.GetEncoding("GB2312").GetString(returnData);
// 再分析,再提交(新浪的防灌水措施)
String timeTagIndex = "", pos3);
String timeTag = returnStr.Substring(pos3, pos4 - pos3);
String datetimeIndex = "", pos3);
String dateTime = returnStr.Substring(pos3, pos4 - pos3);
dateTime = System.Web.HttpUtility.UrlEncode(dateTime, Encoding.GetEncoding
("GB2312"));
String doCommentPostStr = "hidecnt=1";
doCommentPostStr = doCommentPostStr + "&" + clubStr;
doCommentPostStr = doCommentPostStr + "&page=0";
doCommentPostStr = doCommentPostStr + "&top_title=";
doCommentPostStr = doCommentPostStr + "&top_url=";
doCommentPostStr = doCommentPostStr + "&timetag=" + timeTag;
doCommentPostStr = doCommentPostStr + "&datetime0=" + dateTime;
doCommentPostStr = doCommentPostStr + "&uid0=" + userName;
doCommentPostStr = doCommentPostStr + "&content0=" + content;
postData = Encoding.ASCII.GetBytes(doCommentPostStr);
command.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
command.Headers.Add("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;
.NET CLR 1.1.4322)");
command.Headers.Add("Accept", "*/*)");
command.Headers.Add("Referer", "http://comment.sina.com.cn/cgi-
bin/comment/comment_do.cgi");
command.Headers.Add("Cookie", cookie);
returnData = command.UploadData("http://comment.sina.com.cn/cgi-
bin/comment/comment.cgi", "POST", postData);
returnStr = Encoding.GetEncoding("GB2312").GetString(returnData);
System.Console.WriteLine("/r/n***************發貼成功****************");
System.Console.WriteLine(clubStr);
System.Console.WriteLine("***************發貼成功****************");
} // if(pos3 >= 0)
} // if(pos3 >= 0)
else
{
System.Console.WriteLine("/r/n***************接收到錯誤的信息****************");
System.Console.WriteLine(returnStr);
System.Console.WriteLine("***************接收到錯誤的信息****************");
}
}
catch(Exception e)
{
System.Console.WriteLine("/r/n***************發送異常****************");
System.Console.WriteLine(e.Message);
System.Console.WriteLine("***************發貼成功****************");
}
System.Threading.Thread.Sleep(10 * 1000);
}
}
}
}
using System;
using System.IO;
using System.Net; using System.Collections.Specialized;
using System.Text;
namespace sina1
{
///
/// Summary description for Class1.
///
class Class1
{
///
/// The main entry point for the application.
///
[STAThread]
static void Main(string[] args)
{
// test3();
// return;
//
// test1();
// return;
WebClient clubIndexRequest = new WebClient();
clubIndexRequest.Headers.Add("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT
5.1; .NET CLR 1.1.4322)");
clubIndexRequest.Headers.Add("Accept", "*/*)");
Stream stream = clubIndexRequest.OpenRead("http://house.sina.com.cn/allclub/index.html");
StreamReader reader = new StreamReader(stream);
String clubIndexResponse = reader.ReadToEnd();
String url = "href=http://comment.sina.com.cn/cgi-bin/comment/comment.cgi";
int pos1 = 0;
int pos2 = 0;
String userName = System.Web.HttpUtility.UrlEncode("抗議松下熱水器",
Encoding.GetEncoding("GB2312"));
string rawContent = "恐怖的鬆_下熱水器/r/n我本來不想買小_日本的東西的,但是老婆做主,買了
一個鬆_下的燃氣熱水器,花了1千8百多大洋/r/n沒想到安裝的時候還收了我522元,522元啊!/r/n今天
打投訴電話,居然說還有收8百多的!/r/n各位業主,買鬆_下熱水器的時候小心啊,說不定象我這樣當了
冤大頭。/r/n我可以提供證據。";
String content = System.Web.HttpUtility.UrlEncode(rawContent, Encoding.GetEncoding
("GB2312"));
while((pos1 = clubIndexResponse.IndexOf(url, pos2)) >= 0)
{
// 分析業主論壇
pos1 += url.Length + 1;
pos2 = clubIndexResponse.IndexOf(" ", pos1);
String clubStr = clubIndexResponse.Substring(pos1, pos2 - pos1);
// 預提交(新浪的防灌水措施)
// 創建post數據
String postStr = clubStr;
postStr = postStr + "&top_title=";
postStr = postStr + "&top_url=";
postStr = postStr + "&user=" + userName;
postStr = postStr + "&password=" + password;
postStr = postStr + "&content=" + content;
postStr = postStr + "&temp_content=" + content;
byte [] postData = Encoding.ASCII.GetBytes(postStr);
WebClient command = new WebClient();
command.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
command.Headers.Add("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;
.NET CLR 1.1.4322)");
command.Headers.Add("Accept", "*/*)");
try
{
byte [] returnData = command.UploadData("http://comment.sina.com.cn/cgi-
bin/comment/comment_do.cgi", "POST", postData);
String cookie = command.ResponseHeaders["Set-Cookie"];
String returnStr = Encoding.GetEncoding("GB2312").GetString(returnData);
// 再分析,再提交(新浪的防灌水措施)
String timeTagIndex = "", pos3);
String timeTag = returnStr.Substring(pos3, pos4 - pos3);
String datetimeIndex = "", pos3);
String dateTime = returnStr.Substring(pos3, pos4 - pos3);
dateTime = System.Web.HttpUtility.UrlEncode(dateTime, Encoding.GetEncoding
("GB2312"));
String doCommentPostStr = "hidecnt=1";
doCommentPostStr = doCommentPostStr + "&" + clubStr;
doCommentPostStr = doCommentPostStr + "&page=0";
doCommentPostStr = doCommentPostStr + "&top_title=";
doCommentPostStr = doCommentPostStr + "&top_url=";
doCommentPostStr = doCommentPostStr + "&timetag=" + timeTag;
doCommentPostStr = doCommentPostStr + "&datetime0=" + dateTime;
doCommentPostStr = doCommentPostStr + "&uid0=" + userName;
doCommentPostStr = doCommentPostStr + "&content0=" + content;
postData = Encoding.ASCII.GetBytes(doCommentPostStr);
command.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
command.Headers.Add("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;
.NET CLR 1.1.4322)");
command.Headers.Add("Accept", "*/*)");
command.Headers.Add("Referer", "http://comment.sina.com.cn/cgi-
bin/comment/comment_do.cgi");
command.Headers.Add("Cookie", cookie);
returnData = command.UploadData("http://comment.sina.com.cn/cgi-
bin/comment/comment.cgi", "POST", postData);
returnStr = Encoding.GetEncoding("GB2312").GetString(returnData);
System.Console.WriteLine("/r/n***************發貼成功****************");
System.Console.WriteLine(clubStr);
System.Console.WriteLine("***************發貼成功****************");
} // if(pos3 >= 0)
} // if(pos3 >= 0)
else
{
System.Console.WriteLine("/r/n***************接收到錯誤的信息****************");
System.Console.WriteLine(returnStr);
System.Console.WriteLine("***************接收到錯誤的信息****************");
}
}
catch(Exception e)
{
System.Console.WriteLine("/r/n***************發送異常****************");
System.Console.WriteLine(e.Message);
System.Console.WriteLine("***************發貼成功****************");
}
System.Threading.Thread.Sleep(10 * 1000);
}
}
}
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.