// Сообщение в лог
project.SendWarningToLog("", "Переподключение сети!", true);
string protocol = project.Variables["Protocol"].Value; // http:// или socks5://
string proxy = project.Variables["Proxy"].Value;
string userAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0";
string host = project.Variables["Host"].Value; // например, 192.168.1.1
// GET запрос
var resultGet = ZennoPoster.HttpGet(
"http://" + host + "/html/mobileconnection.html",
protocol + proxy,
"UTF-8",
ZennoLab.InterfacesLibrary.Enums.Http.ResponceType.HeaderAndBody,
30000,
string.Empty,
userAgent,
true,
5,
AdditionalHeaders: new[] {
"Host: " + host,
"Accept: */*",
"Accept-Language: ru-RU",
"Connection: keep-alive",
"Referer: http://" + host + "/html/home.html"
}
);
// Парсим Set-Cookie и csrf_token
Match matchCookie = Regex.Match(resultGet, "(?<=Set-Cookie: ).*?(?=;)");
Match matchCsrf_token = Regex.Match(resultGet, "(?<=\"csrf_token\" content=\").*?(?=\")");
if (!matchCookie.Success || !matchCsrf_token.Success)
return null;
string cookies = matchCookie.Value;
string csrf_token = matchCsrf_token.Value;
// POST Отключение
var resultPost = ZennoPoster.HttpPost(
"http://" + host + "/api/dialup/mobile-dataswitch",
"<?xml version=\"1.0\" encoding=\"UTF-8\"?><request><dataswitch>0</dataswitch></request>",
"application/x-www-form-urlencoded",
protocol + proxy,
"UTF-8",
ZennoLab.InterfacesLibrary.Enums.Http.ResponceType.BodyOnly,
30000,
cookies,
userAgent,
true,
5,
AdditionalHeaders: new[] {
"Host: " + host,
"Accept: */*",
"Accept-Language: ru-RU",
"Accept-Encoding: gzip, deflate",
"DNT: 1",
"Content-Type: application/x-www-form-urlencoded; charset=UTF-8",
"__RequestVerificationToken: " + csrf_token,
"X-Requested-With: XMLHttpRequest",
"Connection: keep-alive",
"Referer: http://" + host + "/html/mobileconnection.html"
}
);
// Пауза
Thread.Sleep(2 * 1000);
// GET запрос 2
resultGet = ZennoPoster.HttpGet(
"http://" + host + "/html/mobileconnection.html",
protocol + proxy,
"UTF-8",
ZennoLab.InterfacesLibrary.Enums.Http.ResponceType.HeaderAndBody,
30000,
string.Empty,
userAgent,
true,
5,
AdditionalHeaders: new[] {
"Host: " + host,
"Accept: */*",
"Accept-Language: ru-RU",
"Connection: keep-alive",
"Referer: http://" + host + "/html/home.html"
}
);
// Парсим Set-Cookie и csrf_token
matchCookie = Regex.Match(resultGet, "(?<=Set-Cookie: ).*?(?=;)");
matchCsrf_token = Regex.Match(resultGet, "(?<=\"csrf_token\" content=\").*?(?=\")");
if (!matchCookie.Success || !matchCsrf_token.Success)
return null;
cookies = matchCookie.Value;
csrf_token = matchCsrf_token.Value;
// POST Подключение
resultPost = ZennoPoster.HttpPost(
"http://" + host + "/api/dialup/mobile-dataswitch",
"<?xml version=\"1.0\" encoding=\"UTF-8\"?><request><dataswitch>1</dataswitch></request>",
"application/x-www-form-urlencoded",
protocol + proxy,
"UTF-8",
ZennoLab.InterfacesLibrary.Enums.Http.ResponceType.BodyOnly,
30000,
cookies,
userAgent,
true,
5,
AdditionalHeaders: new[] {
"Host: " + host,
"Accept: */*",
"Accept-Language: ru-RU",
"Accept-Encoding: gzip, deflate",
"DNT: 1",
"Content-Type: application/x-www-form-urlencoded; charset=UTF-8",
"__RequestVerificationToken: " + csrf_token,
"X-Requested-With: XMLHttpRequest",
"Connection: keep-alive",
"Referer: http://" + host + "/html/mobileconnection.html"
}
);
// Рандомная пауза
Random rnd = new Random();
Thread.Sleep(rnd.Next(7, 11) * 1000);