// Сообщение в лог
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["proxy_host"].Value; // например, 192.168.1.1
// GET Получаем токен
var resultGet = ZennoPoster.HttpGet(
"http://" + host + "/api/webserver/SesTokInfo",
proxy,
"UTF-8",
ZennoLab.InterfacesLibrary.Enums.Http.ResponceType.HeaderAndBody,
30000,
string.Empty,
userAgent,
true,
5
);
// Парсим Set-Cookie и csrf_token
Match matchCookie = Regex.Match(resultGet, "(?<=<SesInfo>).*(?=</SesInfo>)");
Match matchCsrf_token = Regex.Match(resultGet, "(?<=<TokInfo>).*(?=</TokInfo>)");
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",
"<request><dataswitch>0</dataswitch></request>",
"",
proxy,
"UTF-8",
ZennoLab.InterfacesLibrary.Enums.Http.ResponceType.BodyOnly,
30000,
cookies,
userAgent,
true,
5,
AdditionalHeaders: new[] {
"__RequestVerificationToken: " + csrf_token,
}
);
Thread.Sleep(3 * 1000);
// GET Получаем токен
resultGet = ZennoPoster.HttpGet(
"http://" + host + "/api/webserver/SesTokInfo",
proxy,
"UTF-8",
ZennoLab.InterfacesLibrary.Enums.Http.ResponceType.HeaderAndBody,
30000,
string.Empty,
userAgent,
true,
5
);
// Парсим Set-Cookie и csrf_token
matchCookie = Regex.Match(resultGet, "(?<=<SesInfo>).*(?=</SesInfo>)");
matchCsrf_token = Regex.Match(resultGet, "(?<=<TokInfo>).*(?=</TokInfo>)");
if (!matchCookie.Success || !matchCsrf_token.Success)
return null;
cookies = matchCookie.Value;
csrf_token = matchCsrf_token.Value;
// POST Переключение на 3g
resultPost = ZennoPoster.HttpPost(
"http://" + host + "/api/net/net-mode",
"<request><NetworkMode>02</NetworkMode><NetworkBand>3FFFFFFF</NetworkBand><LTEBand>800C5</LTEBand></request>",
"",
proxy,
"UTF-8",
ZennoLab.InterfacesLibrary.Enums.Http.ResponceType.BodyOnly,
30000,
cookies,
userAgent,
true,
5,
AdditionalHeaders: new[] {
"__RequestVerificationToken: " + csrf_token,
}
);
Thread.Sleep(3 * 1000);
// GET Получаем токен
resultGet = ZennoPoster.HttpGet(
"http://" + host + "/api/webserver/SesTokInfo",
proxy,
"UTF-8",
ZennoLab.InterfacesLibrary.Enums.Http.ResponceType.HeaderAndBody,
30000,
string.Empty,
userAgent,
true,
5
);
// Парсим Set-Cookie и csrf_token
matchCookie = Regex.Match(resultGet, "(?<=<SesInfo>).*(?=</SesInfo>)");
matchCsrf_token = Regex.Match(resultGet, "(?<=<TokInfo>).*(?=</TokInfo>)");
if (!matchCookie.Success || !matchCsrf_token.Success)
return null;
cookies = matchCookie.Value;
csrf_token = matchCsrf_token.Value;
// POST Переключение на 4g-3g lte-UMTS
resultPost = ZennoPoster.HttpPost(
"http://" + host + "/api/net/net-mode",
"<request><NetworkMode>0302</NetworkMode><NetworkBand>3FFFFFFF</NetworkBand><LTEBand>800C5</LTEBand></request>",
"",
proxy,
"UTF-8",
ZennoLab.InterfacesLibrary.Enums.Http.ResponceType.BodyOnly,
30000,
cookies,
userAgent,
true,
5,
AdditionalHeaders: new[] {
"__RequestVerificationToken: " + csrf_token,
}
);
Thread.Sleep(3 * 1000);
// GET Получаем токен
resultGet = ZennoPoster.HttpGet(
"http://" + host + "/api/webserver/SesTokInfo",
proxy,
"UTF-8",
ZennoLab.InterfacesLibrary.Enums.Http.ResponceType.HeaderAndBody,
30000,
string.Empty,
userAgent,
true,
5
);
// Парсим Set-Cookie и csrf_token
matchCookie = Regex.Match(resultGet, "(?<=<SesInfo>).*(?=</SesInfo>)");
matchCsrf_token = Regex.Match(resultGet, "(?<=<TokInfo>).*(?=</TokInfo>)");
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",
"<request><dataswitch>1</dataswitch></request>",
"",
proxy,
"UTF-8",
ZennoLab.InterfacesLibrary.Enums.Http.ResponceType.BodyOnly,
30000,
cookies,
userAgent,
true,
5,
AdditionalHeaders: new[] {
"__RequestVerificationToken: " + csrf_token,
}
);