add projects
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 6s

This commit is contained in:
admin
2026-03-17 17:25:08 +03:00
parent fc01f07d7c
commit ed55e77e98
39 changed files with 4430 additions and 8 deletions
+90
View File
@@ -0,0 +1,90 @@
using System.Net;
namespace ChekTimeDahua
{
internal class Program
{
static async Task Main(string[] args)
{
#if DEBUG
args = new string[4];
args[0] = "check";
args[1] = "172.16.50.14";
args[2] = "admin";
args[3] = "4NUDZhJ7";
#endif
string server, login, password;
if (args.Length != 4) return;
server = args[1];
login = args[2];
password = args[3];
switch (args[0])
{
case "check":
string baseUrl = $"http://{server}";
var credCache = new CredentialCache();
credCache.Add(new Uri(baseUrl), "Digest", new NetworkCredential(login, password));
using (var handler = new HttpClientHandler
{
Credentials = credCache,
ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => true
})
using (var httpClient = new HttpClient(handler))
{
string requestUrl = $"{baseUrl}/cgi-bin/global.cgi?action=getCurrentTime";
var response = await httpClient.GetAsync(requestUrl);
try
{
response.EnsureSuccessStatusCode();
}
catch (Exception)
{
Console.WriteLine("1");
return;
}
var r = await response.Content.ReadAsStringAsync();
var r2 = Convert.ToDateTime(r.Split("=")[1]);
if (r2 <= DateTime.Now.AddMinutes(2) && r2 >= DateTime.Now.AddMinutes(-2))
Console.WriteLine("0");
else Console.WriteLine("1");
}
break;
case "update":
string baseUrlU = $"http://{server}";
var credCacheU = new CredentialCache();
credCacheU.Add(new Uri(baseUrlU), "Digest", new NetworkCredential(login, password));
using (var handler = new HttpClientHandler
{
Credentials = credCacheU,
ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => true
})
using (var httpClient = new HttpClient(handler))
{
string requestUrl = $"{baseUrlU}/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("1");
return;
}
var r = await response.Content.ReadAsStringAsync();
//r = r.Replace("\r\n", "");
if (r.StartsWith("OK"))
{
Console.WriteLine("0");
}
else Console.WriteLine("1");
}
break;
default:
break;
}
}
}
}