让代码更简单

当前位置:代码狗 > 资源分享 > 正文

C#实现百度统计后台推广刷百度统计流量

重要:本文最后更新于2020-03-26 08:27:48,某些文章具有时效性,若有错误或已失效,请在下方留言或联系代码狗

百度统计后台推广刷百度统计流量是怎么实现的?本文教你C#实现百度统计后台推广刷百度统计流量。百度统计是通过js发送请求到百度统计后台实现的,所以只需要分析百度统计js做了哪些事情(抓包),然后自己封包模拟提交即可。

C#实现百度统计后台推广刷百度统计流量

C#实现百度统计后台推广刷百度统计流量

百度统计接口信息

请求方式:get

请求地址:https://hm.baidu.com/hm.gif?” + “&rnd” + 随机字符串10个 + “&sn=” + 随机字符串10个+ “&su=” + 搜索地址 + “&si=” + 统计代码

请求头来源:推广地址

C#发包代码

WebHeaderCollection headers = new WebHeaderCollection();
headers.Add("Accept-Encoding", "gzip, deflate, br");
headers.Add("Sec-Fetch-Site", "cross-site");
headers.Add("Sec-Fetch-Mode", "no-cors");
headers.Add("ccept-Language", "zh-CN,zh;q=0.9");

string su = "https://www.sogou.com/tx?query=" + System.Web.HttpUtility.UrlEncode(str);
string url = "https://hm.baidu.com/hm.gif?" + "&rnd" + GetRandomString(10, true, false, false, false, "") + "&sn=" + GetRandomString(10, true, false, false, false, "") + "&su=" + su + "&si=" + tjdm;

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
CookieContainer myCookieContainer = new CookieContainer();
myCookieContainer.Add(new Cookie("HMVT", "0d1289ab5f0206c6f2a6d876bcbf13b6|1583373001|") { Domain = "hm.baidu.com" });
myCookieContainer.Add(new Cookie("HMACCOUNT", Encrypt16(GetRandomString(32, true, true, true, false, "")).ToUpper()) { Domain = "hm.baidu.com" });
request.CookieContainer = myCookieContainer;
request.Referer = tgurl;
request.Accept = "Accept:image/webp,image/apng,image/*,*/*;q=0.8";
request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Safari/537.36 Core/1.70.3741.400 QQBrowser/10.5.3863.400";
request.Host = "hm.baidu.com";
request.KeepAlive = true;
request.Method = "GET";
Encoding encoding = Encoding.UTF8;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream getStream = response.GetResponseStream();
StreamReader streamreader = new StreamReader(getStream);
String result = streamreader.ReadToEnd();

随机字符串

 ///<summary>
///生成随机字符串 
///</summary>
///<param name="length">目标字符串的长度</param>
///<param name="useNum">是否包含数字,1=包含,默认为包含</param>
///<param name="useLow">是否包含小写字母,1=包含,默认为包含</param>
///<param name="useUpp">是否包含大写字母,1=包含,默认为包含</param>
///<param name="useSpe">是否包含特殊字符,1=包含,默认为不包含</param>
///<param name="custom">要包含的自定义字符,直接输入要包含的字符列表</param>
///<returns>指定长度的随机字符串</returns>
public static string GetRandomString(int length, bool useNum, bool useLow, bool useUpp, bool useSpe, string custom)
{
byte[] b = new byte[4];
new System.Security.Cryptography.RNGCryptoServiceProvider().GetBytes(b);
Random r = new Random(BitConverter.ToInt32(b, 0));
string s = null, str = custom;
if (useNum == true) { str += "0123456789"; }
if (useLow == true) { str += "abcdefghijklmnopqrstuvwxyz"; }
if (useUpp == true) { str += "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; }
if (useSpe == true) { str += "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"; }
for (int i = 0; i < length; i++)
{
s += str.Substring(r.Next(0, str.Length - 1), 1);
}
return s;
}

MD5到大写

public string Encrypt16(string strPwd)
{
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
string t2 = BitConverter.ToString(md5.ComputeHash(UTF8Encoding.Default.GetBytes(strPwd)), 4, 8);
t2 = t2.Replace("-", "");
return t2.ToLower();
}

重点是请求头,如果请求头信息不对,百度统计会过滤掉,还有cookies。另外,百度搜索词采取了另类统计方式,目前暂不支持,其它搜索引擎正常使用。

文件下载

要查看更多文章内容,请您先登录/注册

感觉很棒!可以赞赏支持我哟~

赞(0) 打赏

评论 1

  1. #1

    这么厉害

    兴化人才网1周前 (03-26)回复
×

请作者吃根烤肠!

支付宝