最近看到網上一投票。
下載了個抓包工具
簡單的抓了下數據包。。。內容如下
POST /Vote_doIP.asp HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/x-ms-application, application/x-ms-xbap,
application/vnd.ms-xpsdocument, application/xaml+xml, */*
Referer: http://show.qingdaobaby.com/Vote.asp?id=1247
Accept-Language: zh-cn
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)
Host: show.qingdaobaby.com
Content-Length: 59
Connection: Keep-Alive
Cache-Control: no-cache
Cookie: ASPSESSIONIDQQBBTADB=GNKABLHAIHABJFEGDJBHLFAK; cnzz_a634504=4; sin634504=none; rtime=0; ltime=1322322790279; cnzz_eid=99430049-1322321123-;
oesun=vitistime=2011%2D11%2D26+23%3A52%3A15
ValidCode=G%26KG&pid=1247&Submitok=%C8%B7%C8%CF%CD%B6%C6%B1
上面是抓包工具抓到的內容。。
從上面的內容可以看出
數據接收頁面是這個www.2cto.com
http://show.qingdaobaby.com/Vote_doIP.asp
數據發送頁面是
http://show.qingdaobaby.com/Vote.asp?id=1247
post的數據是 ValidCode=G%26KG&pid=1247&Submitok=%C8%B7%C8%CF%CD%B6%C6%B1 就是驗證碼。跟投票的編號 跟按鈕的value
就這些東西
因為這個系統需要驗證碼 又找了下驗證碼的地址
http://show.qingdaobaby.com/getcode.asp
要解決的問題有
1.驗證碼問題
只要不第二次訪問getcode.asp頁面,服務器session中存的驗證碼不變。(有些網站比較完驗證碼後,不把session裡的驗證碼清空)
2.ip地址限制問題
adsl網絡換ip很容易
用web代理也可以
開發工具vs2008
主要代碼
1.得到cookie的代碼
public void GetSession(string url)
{
cc = new CookieContainer();
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.CookieContainer = cc;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
cc.Add(response.Cookies);
}
2.取出當前cookie的驗證碼內容把它顯示到 pictureBox中
string url = "http://http://show.qingdaobaby.com/getcode.asp";
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
request.CookieContainer = cc;
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
System.IO.Stream responseStream = response.GetResponseStream();
this.pictureBox1.Image = Image.FromStream(responseStream);
3.可以輸入驗證碼發送post請求了 session不過期,驗證碼是同一個 ,post代碼
ASCIIEncoding encoding = new ASCIIEncoding();
string postData = "ValidCode=" + this.textBox2.Text + "&pid=1247";
byte[] data = encoding.GetBytes(postData);
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("http://show.qingdaobaby.com/Vote_doIP.asp");
myRequest.Method = "POST";
myRequest.ContentType = "application/x-www-form-urlencoded";//這個必須要加
myRequest.ContentLength = data.Length;
myRequest.Referer = "http://show.qingdaobaby.com";
myRequest.CookieContainer = cc;
Stream newStream = myRequest.GetRequestStream();
newStream.Write(data, 0, data.Length);
newStream.Close();
HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.Default);
string content = reader.ReadToEnd();
4.adsl網絡下可以用dos命令rasdial 來換ip
private void com(string command)
{
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.Arguments = "/c " + command;
p.StartInfo.CreateNoWindow =true;
//MessageBox.Show(arg);
//下面兩句必須加
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.Start();
string output = p.StandardOutput.ReadToEnd();
//MessageBox.Show(output);
//Console.WriteLine(output);
}
Thread.Sleep(1000);
com("rasdial \"test\" /DISCONNECT"); //斷開adsl連接
Thread.Sleep(1000);
com("rasdial \"test\" XXXXXX XXXXXX"); //adsl連接名稱,用戶名,密碼。
Thread.Sleep(10000);
5.通過代理可以用下面的代碼
WebProxy proxy = new WebProxy("xxxxxxxx", 80);
request.Proxy = proxy;
使用方法 :先點“得到cookie按鈕”,再點“取驗證碼”,在文本框裡輸入輸入驗證碼後,最後點“自動投票”。
如果你發現有什麼不合理的,需要改進的地方,或者你有什麼更好的實現方法郵件聯系[email protected](qq常年不在線,郵件聯系) 朱曉 。相互交流 謝謝
源碼下載地址 http://download.csdn.net/detail/xiaoxiao108/3864961 根據需要自己修改源碼
作者 xiaoxiao108