This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System.Net;
|
||||
using System.Net.NetworkInformation;
|
||||
|
||||
namespace ChekTimeDahua
|
||||
{
|
||||
@@ -8,7 +9,7 @@ namespace ChekTimeDahua
|
||||
{
|
||||
#if DEBUG
|
||||
args = new string[4];
|
||||
args[0] = "check";
|
||||
args[0] = "set";
|
||||
args[1] = "172.16.50.14";
|
||||
args[2] = "admin";
|
||||
args[3] = "4NUDZhJ7";
|
||||
@@ -55,7 +56,7 @@ namespace ChekTimeDahua
|
||||
string baseUrlU = $"http://{server}";
|
||||
var credCacheU = new CredentialCache();
|
||||
credCacheU.Add(new Uri(baseUrlU), "Digest", new NetworkCredential(login, password));
|
||||
using (var handler = new HttpClientHandler
|
||||
using (var handler = new HttpClientHandler
|
||||
{
|
||||
Credentials = credCacheU,
|
||||
ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => true
|
||||
@@ -82,6 +83,55 @@ namespace ChekTimeDahua
|
||||
else Console.WriteLine("1");
|
||||
}
|
||||
break;
|
||||
case "set":
|
||||
var list = new List<string>();
|
||||
var lines = File.ReadAllLines("listCam.csv");
|
||||
foreach (var line in lines)
|
||||
{
|
||||
list.Add(line);
|
||||
}
|
||||
foreach (var host in list)
|
||||
{
|
||||
using (Ping ping = new Ping())
|
||||
{
|
||||
PingReply pingReply = ping.Send(host);
|
||||
if (pingReply.Status != IPStatus.Success)
|
||||
{
|
||||
Console.WriteLine($"{host}\t NO PING");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
string baseUrlS = $"http://{host}";
|
||||
var credCacheS = new CredentialCache();
|
||||
credCacheS.Add(new Uri(baseUrlS), "Digest", new NetworkCredential(login, password));
|
||||
using (var handler = new HttpClientHandler
|
||||
{
|
||||
Credentials = credCacheS,
|
||||
ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => true
|
||||
})
|
||||
using (var httpClient = new HttpClient(handler))
|
||||
{
|
||||
string requestUrl = $"{baseUrlS}/cgi-bin/global.cgi?action=setCurrentTime&time={DateTime.Now:yyyy-MM-dd HH:mm:ss}";
|
||||
var response = await httpClient.GetAsync(requestUrl);
|
||||
try
|
||||
{
|
||||
response.EnsureSuccessStatusCode();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
Console.WriteLine($"{host}\t Rechek");
|
||||
}
|
||||
var r = await response.Content.ReadAsStringAsync();
|
||||
//r = r.Replace("\r\n", "");
|
||||
if (r.StartsWith("OK"))
|
||||
{
|
||||
Console.WriteLine($"{host}\t OK");
|
||||
}
|
||||
else Console.WriteLine($"{host}\t Rechek");
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user