diff --git a/AddHostToProxy/Program.cs b/AddHostToProxy/Program.cs index e38ea0d..15ed596 100644 --- a/AddHostToProxy/Program.cs +++ b/AddHostToProxy/Program.cs @@ -19,7 +19,7 @@ namespace AddHostToProxy var lsDomain = new List(); var _meta = new Meta(); host.meta = _meta; - lsDomain.Add(item.Value+".vnk.security.local"); + lsDomain.Add(item.Value+"-vnk.security.local"); host.domain_names = lsDomain; host.forward_host = item.Key; var str2 = await AddProxyHostAsync(str, host); diff --git a/CheckEVS/Program.cs b/CheckEVS/Program.cs index 19e6cd0..8fd1624 100644 --- a/CheckEVS/Program.cs +++ b/CheckEVS/Program.cs @@ -1,12 +1,8 @@ using CheckEVS; -using System; -using System.Net.Http; -using System.Net.Http.Json; using System.Security.Cryptography; using System.Text; using System.Text.Json; using System.Text.Json.Serialization; -using System.Threading.Tasks; namespace DahuaDiskChecker { @@ -18,10 +14,11 @@ namespace DahuaDiskChecker //Console.WriteLine("=== ПРОВЕРКА СОСТОЯНИЯ ДИСКА DAHUA ==="); #if DEBUG - Console.WriteLine("Введи ip-адрес EVS:"); - server = Console.ReadLine(); - Console.WriteLine("Введи номер диска: (0 - количество неисправных, 1-24 - статус указанного"); - int diskNumber = Convert.ToInt32(Console.ReadLine()); + Start: + //Console.WriteLine("Введи ip-адрес EVS:"); + server = "172.16.48.144"; + //Console.WriteLine("Введи номер диска: (0 - количество неисправных, 1-24 - статус указанного"); + int diskNumber = 6; #else // Парсинг аргументов @@ -74,6 +71,8 @@ namespace DahuaDiskChecker } #if DEBUG Console.ReadKey(); + Console.WriteLine("======================================="); + goto Start; #endif //Console.WriteLine(new string('=', 40)); @@ -82,6 +81,7 @@ namespace DahuaDiskChecker { Console.WriteLine($"❌ Ошибка: {ex.Message}"); } + } private static async Task PromoPrint() diff --git a/ChekTimeDahua/ChekTimeDahua.csproj b/ChekTimeDahua/ChekTimeDahua.csproj index dfadba7..d0b34df 100644 --- a/ChekTimeDahua/ChekTimeDahua.csproj +++ b/ChekTimeDahua/ChekTimeDahua.csproj @@ -8,4 +8,10 @@ + + + Always + + + diff --git a/ChekTimeDahua/Program.cs b/ChekTimeDahua/Program.cs index c7e7d39..2036011 100644 --- a/ChekTimeDahua/Program.cs +++ b/ChekTimeDahua/Program.cs @@ -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(); + 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; } diff --git a/ChekTimeDahua/listCam.csv b/ChekTimeDahua/listCam.csv new file mode 100644 index 0000000..fe71407 --- /dev/null +++ b/ChekTimeDahua/listCam.csv @@ -0,0 +1,16 @@ +172.16.54.28 +172.16.54.29 +172.16.54.30 +172.16.54.31 +172.16.54.32 +172.16.54.33 +172.16.54.34 +172.16.54.35 +172.16.54.36 +172.16.54.37 +172.16.54.38 +172.16.54.39 +172.16.54.40 +172.16.54.41 +172.16.54.42 +172.16.54.43 \ No newline at end of file diff --git a/GenerateYAMLforZabbix/GenerateYAMLforZabbix.csproj b/GenerateYAMLforZabbix/GenerateYAMLforZabbix.csproj new file mode 100644 index 0000000..210ad2e --- /dev/null +++ b/GenerateYAMLforZabbix/GenerateYAMLforZabbix.csproj @@ -0,0 +1,23 @@ + + + + Exe + net9.0 + enable + enable + + + + + + + + + Always + + + Always + + + + diff --git a/GenerateYAMLforZabbix/Program.cs b/GenerateYAMLforZabbix/Program.cs new file mode 100644 index 0000000..df51f6c --- /dev/null +++ b/GenerateYAMLforZabbix/Program.cs @@ -0,0 +1,39 @@ +using System.Text; + +namespace GenerateYAMLforZabbix +{ + internal class Program + { + static void Main(string[] args) + { + var list = new List(); + var lines = File.ReadAllLines("listCam.txt", Encoding.UTF8); + foreach (var line in lines) + { + var uzel = line.Split(';'); + list.Add(uzel); + } + foreach (var host in list) + { + //var act4 = host[0].Split(".")[3]; + var text = $""+ + $" - host: {host[0]}\r\n" + + $" name: (СПб){host[1]}\r\n" + + $" templates:\r\n" + + $" - name: 'SEC Dahua Camera SNMP'\r\n" + + $" groups:\r\n" + + $" - name: dahua.cam.spb\r\n" + + $" interfaces:\r\n" + + $" - type: SNMP\r\n" + + $" ip: {host[0]}\r\n" + + $" port: '161'\r\n" + + $" details:\r\n" + + $" community: '{{$SNMP_COMMUNITY}}'\r\n" + + $" interface_ref: if1\r\n" + + $" inventory_mode: DISABLED\r\n"; + + File.AppendAllText("hosts.yaml", text, Encoding.UTF8); + } + } + } +} \ No newline at end of file diff --git a/GenerateYAMLforZabbix/hosts.yaml b/GenerateYAMLforZabbix/hosts.yaml new file mode 100644 index 0000000..8b2da8b --- /dev/null +++ b/GenerateYAMLforZabbix/hosts.yaml @@ -0,0 +1,6 @@ +zabbix_export: + version: '7.0' + host_groups: + - uuid: 1c44fc80770242e5a82b2e06b9b368b2 + name: dahua.cam.spb + hosts: diff --git a/GenerateYAMLforZabbix/listCam.txt b/GenerateYAMLforZabbix/listCam.txt new file mode 100644 index 0000000..b39ccf8 --- /dev/null +++ b/GenerateYAMLforZabbix/listCam.txt @@ -0,0 +1,42 @@ +172.22.10.51;Пом.545-2 +172.22.10.52;Пом.519-1 +172.22.10.53;Пом.511-1 +172.22.10.54;Пом.517-2 +172.22.10.55;Эвак. Выход-3 +172.22.10.56;Пом.545-коридор +172.22.10.57;Ресепшн-1 +172.22.10.58;Пом.545-3 +172.22.10.59;Пом.521-3 +172.22.10.60;Пом.535 к лифтам +172.22.10.61;Пом.515-2 +172.22.10.62;Пом.511-2 +172.22.10.63;Пом.517-1 +172.22.10.64;Пом.521-1 +172.22.10.65;Пом.535-коридор +172.22.10.66;Пом.526-столовая +172.22.10.67;Пом.545-4 +172.22.10.68;Пом.532-2 +172.22.10.69;Пом.515-1 +172.22.10.70;Пом.535-1 +172.22.10.71;Эвак. Выход-2 +172.22.10.72;Пом.545-1 +172.22.10.73;Ресепшн-2 +172.22.10.74;Пом.521-2 +172.22.10.93;Пом.319-столовая +172.22.10.94;Пом.313-1 +172.22.10.95;Пом.321-1 +172.22.10.96;Коридор от лифт. холла +172.22.10.97;Пом.321-2 +172.22.10.98;Коридор к лифт. холлу +172.22.10.99;Пом.313-2 +172.22.10.100;Пом.323-2 +172.22.10.101;Пом.323-1 +172.22.10.102;Эвак. Выход +172.22.10.103;Кроссовая +172.22.10.104;Пом.304-1 +172.22.10.105;Пом.304-2 +172.22.10.106;Пом.312 +172.22.10.107;Пом.237 +172.22.10.108;Пом.519-2 +172.22.10.109;Пом.244-1 +172.22.10.110;Пом.244-2 \ No newline at end of file diff --git a/LC_Api/LC_Api.csproj b/LC_Api/LC_Api.csproj index 275433b..9f37b89 100644 --- a/LC_Api/LC_Api.csproj +++ b/LC_Api/LC_Api.csproj @@ -10,7 +10,7 @@ - + diff --git a/LC_ConfigCamer/App.config b/LC_ConfigCamer/App.config index bcb2ae2..46edd75 100644 --- a/LC_ConfigCamer/App.config +++ b/LC_ConfigCamer/App.config @@ -7,7 +7,35 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/LC_ConfigCamer/LC_ConfigCamer.csproj b/LC_ConfigCamer/LC_ConfigCamer.csproj index 6be6c2a..0aa396f 100644 --- a/LC_ConfigCamer/LC_ConfigCamer.csproj +++ b/LC_ConfigCamer/LC_ConfigCamer.csproj @@ -67,43 +67,44 @@ true - - ..\packages\Microsoft.Bcl.AsyncInterfaces.8.0.0\lib\net462\Microsoft.Bcl.AsyncInterfaces.dll + + ..\packages\Microsoft.Bcl.AsyncInterfaces.10.0.5\lib\net462\Microsoft.Bcl.AsyncInterfaces.dll ..\packages\Newtonsoft.Json.13.0.4\lib\net45\Newtonsoft.Json.dll - - ..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll + + ..\packages\System.Buffers.4.6.1\lib\net462\System.Buffers.dll - - ..\packages\System.Memory.4.5.5\lib\net461\System.Memory.dll + + ..\packages\System.IO.Pipelines.10.0.5\lib\net462\System.IO.Pipelines.dll + + + ..\packages\System.Memory.4.6.3\lib\net462\System.Memory.dll - - ..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll + + ..\packages\System.Numerics.Vectors.4.6.1\lib\net462\System.Numerics.Vectors.dll - - ..\packages\System.Runtime.CompilerServices.Unsafe.6.0.0\lib\net461\System.Runtime.CompilerServices.Unsafe.dll + + ..\packages\System.Runtime.CompilerServices.Unsafe.6.1.2\lib\net462\System.Runtime.CompilerServices.Unsafe.dll - - ..\packages\System.Text.Encodings.Web.8.0.0\lib\net462\System.Text.Encodings.Web.dll + + ..\packages\System.Text.Encodings.Web.10.0.5\lib\net462\System.Text.Encodings.Web.dll - - ..\packages\System.Text.Json.8.0.5\lib\net462\System.Text.Json.dll + + ..\packages\System.Text.Json.10.0.5\lib\net462\System.Text.Json.dll - - ..\packages\System.Threading.Channels.8.0.0\lib\net462\System.Threading.Channels.dll + + ..\packages\System.Threading.Channels.10.0.5\lib\net462\System.Threading.Channels.dll - - ..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll - - - ..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll + + ..\packages\System.Threading.Tasks.Extensions.4.6.3\lib\net462\System.Threading.Tasks.Extensions.dll + @@ -177,5 +178,7 @@ Данный проект ссылается на пакеты NuGet, отсутствующие на этом компьютере. Используйте восстановление пакетов NuGet, чтобы скачать их. Дополнительную информацию см. по адресу: http://go.microsoft.com/fwlink/?LinkID=322105. Отсутствует следующий файл: {0}. + + \ No newline at end of file diff --git a/LC_ConfigCamer/packages.config b/LC_ConfigCamer/packages.config index a78ef0f..221f4a7 100644 --- a/LC_ConfigCamer/packages.config +++ b/LC_ConfigCamer/packages.config @@ -1,15 +1,16 @@  - + - - - - - - - - - + + + + + + + + + + \ No newline at end of file diff --git a/SetVideoDataHikvision/Program.cs b/SetVideoDataHikvision/Program.cs new file mode 100644 index 0000000..b851475 --- /dev/null +++ b/SetVideoDataHikvision/Program.cs @@ -0,0 +1,67 @@ +using System.Net; +using System.Net.NetworkInformation; +using System.Text; + +namespace SetVideoDataHikvision +{ + internal class Program + { + static void Main(string[] args) + { + var list = new List(); + 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 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}/ISAPI/System/time"; + + string xmlBody = $@""; + + // Создаем контент для PUT запроса + var content = new StringContent(xmlBody, Encoding.UTF8, "application/xml"); + + // Выполняем PUT запрос + var response = await httpClient.PutAsync(requestUrl, content); + 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"); + } + } + } + } +} diff --git a/SetVideoDataHikvision/SetVideoDataHikvision.csproj b/SetVideoDataHikvision/SetVideoDataHikvision.csproj new file mode 100644 index 0000000..2150e37 --- /dev/null +++ b/SetVideoDataHikvision/SetVideoDataHikvision.csproj @@ -0,0 +1,10 @@ + + + + Exe + net8.0 + enable + enable + + + diff --git a/SettingSNMPDahua/Program.cs b/SettingSNMPDahua/Program.cs new file mode 100644 index 0000000..502b04a --- /dev/null +++ b/SettingSNMPDahua/Program.cs @@ -0,0 +1,149 @@ +using System.Net; +using System.Net.NetworkInformation; + +internal class Program +{ + private static async Task Main(string[] args) + { +#if DEBUG + args = new string[4]; + args[0] = "set"; + args[1] = "172.16.51.2"; + 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; + case "set": + var list = new List(); + 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/configManager.cgi?" + + $"action=setConfig&" + + $"SNMP.Enable=true&" + + $"SNMP.V2Enable=false&" + + $"SNMP.V1Enable=false&" + + $"SNMP.V3Enable=false&" + + $"SNMP.Port=161&" + + $"SNMP.ReadCommon=public&" + + $"SNMP.WriteCommon=private"; + var response = await httpClient.GetAsync(requestUrl); + response.EnsureSuccessStatusCode(); + var r = await response.Content.ReadAsStringAsync(); + if (r.StartsWith("OK")) + { + string requestUrl2 = $"{baseUrlS}/cgi-bin/configManager.cgi?" + + $"action=setConfig&" + + $"SNMP.Enable=true&" + + $"SNMP.V2Enable=true&" + + $"SNMP.V1Enable=false&" + + $"SNMP.V3Enable=false&" + + $"SNMP.Port=161&" + + $"SNMP.ReadCommon=public&" + + $"SNMP.WriteCommon=private"; + var response2 = await httpClient.GetAsync(requestUrl2); + var r2 = await response2.Content.ReadAsStringAsync(); + if (r2.StartsWith("OK")) Console.WriteLine("0"); + else Console.WriteLine("1"); + } + else Console.WriteLine("1"); + } + } + break; + default: + break; + } + } +} \ No newline at end of file diff --git a/SettingSNMPDahua/SettingSNMPDahua.csproj b/SettingSNMPDahua/SettingSNMPDahua.csproj new file mode 100644 index 0000000..d165e11 --- /dev/null +++ b/SettingSNMPDahua/SettingSNMPDahua.csproj @@ -0,0 +1,16 @@ + + + + Exe + net8.0 + enable + enable + + + + + Always + + + + diff --git a/SettingSNMPDahua/listCam.csv b/SettingSNMPDahua/listCam.csv new file mode 100644 index 0000000..892687a --- /dev/null +++ b/SettingSNMPDahua/listCam.csv @@ -0,0 +1,255 @@ +172.16.54.1 +172.16.54.2 +172.16.54.3 +172.16.54.4 +172.16.54.5 +172.16.54.6 +172.16.54.7 +172.16.54.8 +172.16.54.9 +172.16.54.10 +172.16.54.11 +172.16.54.12 +172.16.54.13 +172.16.54.14 +172.16.54.15 +172.16.54.16 +172.16.54.17 +172.16.54.18 +172.16.54.19 +172.16.54.20 +172.16.54.21 +172.16.54.22 +172.16.54.23 +172.16.54.24 +172.16.54.25 +172.16.54.26 +172.16.54.27 +172.16.54.28 +172.16.54.29 +172.16.54.30 +172.16.54.31 +172.16.54.32 +172.16.54.33 +172.16.54.34 +172.16.54.35 +172.16.54.36 +172.16.54.37 +172.16.54.38 +172.16.54.39 +172.16.54.40 +172.16.54.41 +172.16.54.42 +172.16.54.43 +172.16.54.44 +172.16.54.45 +172.16.54.46 +172.16.54.47 +172.16.54.48 +172.16.54.49 +172.16.54.50 +172.16.54.51 +172.16.53.52 +172.16.53.53 +172.16.53.54 +172.16.53.55 +172.16.53.56 +172.16.53.57 +172.16.53.58 +172.16.53.59 +172.16.53.60 +172.16.53.61 +172.16.53.62 +172.16.53.63 +172.16.53.64 +172.16.53.65 +172.16.53.66 +172.16.53.67 +172.16.53.68 +172.16.53.69 +172.16.53.70 +172.16.53.71 +172.16.53.72 +172.16.53.73 +172.16.53.74 +172.16.53.75 +172.16.53.76 +172.16.53.77 +172.16.53.78 +172.16.53.79 +172.16.53.80 +172.16.53.81 +172.16.53.82 +172.16.53.83 +172.16.53.84 +172.16.53.85 +172.16.53.86 +172.16.53.87 +172.16.53.88 +172.16.53.89 +172.16.53.90 +172.16.53.91 +172.16.53.92 +172.16.53.93 +172.16.53.94 +172.16.53.95 +172.16.53.96 +172.16.53.97 +172.16.53.98 +172.16.53.99 +172.16.53.100 +172.16.53.101 +172.16.53.102 +172.16.53.103 +172.16.53.104 +172.16.53.105 +172.16.53.106 +172.16.53.107 +172.16.53.108 +172.16.53.109 +172.16.53.110 +172.16.53.111 +172.16.53.112 +172.16.53.113 +172.16.53.114 +172.16.53.115 +172.16.53.116 +172.16.53.117 +172.16.53.118 +172.16.53.119 +172.16.53.120 +172.16.53.121 +172.16.53.122 +172.16.53.123 +172.16.53.124 +172.16.53.125 +172.16.53.126 +172.16.53.127 +172.16.53.128 +172.16.53.129 +172.16.53.130 +172.16.53.131 +172.16.53.132 +172.16.53.133 +172.16.53.134 +172.16.53.135 +172.16.53.136 +172.16.53.137 +172.16.53.138 +172.16.53.139 +172.16.53.140 +172.16.53.141 +172.16.53.142 +172.16.53.143 +172.16.53.144 +172.16.53.145 +172.16.53.146 +172.16.53.147 +172.16.53.148 +172.16.53.149 +172.16.53.150 +172.16.53.151 +172.16.53.152 +172.16.53.153 +172.16.53.154 +172.16.53.155 +172.16.53.156 +172.16.53.157 +172.16.53.158 +172.16.53.159 +172.16.53.160 +172.16.53.161 +172.16.53.162 +172.16.53.163 +172.16.53.164 +172.16.53.165 +172.16.53.166 +172.16.53.167 +172.16.53.168 +172.16.53.169 +172.16.53.170 +172.16.53.171 +172.16.53.172 +172.16.53.173 +172.16.53.174 +172.16.53.175 +172.16.53.176 +172.16.53.177 +172.16.53.178 +172.16.53.179 +172.16.53.180 +172.16.53.181 +172.16.53.182 +172.16.53.183 +172.16.53.184 +172.16.53.185 +172.16.53.186 +172.16.53.187 +172.16.53.188 +172.16.53.189 +172.16.53.190 +172.16.53.191 +172.16.53.192 +172.16.53.193 +172.16.53.194 +172.16.53.195 +172.16.53.196 +172.16.53.197 +172.16.53.198 +172.16.53.199 +172.16.53.200 +172.16.53.201 +172.16.53.202 +172.16.53.203 +172.16.53.204 +172.16.53.205 +172.16.53.206 +172.16.53.207 +172.16.53.208 +172.16.53.209 +172.16.53.210 +172.16.53.211 +172.16.53.212 +172.16.53.213 +172.16.53.214 +172.16.53.215 +172.16.53.216 +172.16.53.217 +172.16.53.218 +172.16.53.219 +172.16.53.220 +172.16.53.221 +172.16.53.222 +172.16.53.223 +172.16.53.224 +172.16.53.225 +172.16.53.226 +172.16.53.227 +172.16.53.228 +172.16.53.229 +172.16.53.230 +172.16.53.231 +172.16.53.232 +172.16.53.233 +172.16.53.234 +172.16.53.235 +172.16.53.236 +172.16.53.237 +172.16.53.238 +172.16.53.239 +172.16.53.240 +172.16.53.241 +172.16.53.242 +172.16.53.243 +172.16.53.244 +172.16.53.245 +172.16.53.246 +172.16.53.247 +172.16.53.248 +172.16.53.249 +172.16.53.250 +172.16.53.251 +172.16.53.252 +172.16.53.253 +172.16.53.254 +172.16.53.255 \ No newline at end of file diff --git a/Strela/Controllers/WeatherForecastController.cs b/Strela/Controllers/WeatherForecastController.cs new file mode 100644 index 0000000..940ecba --- /dev/null +++ b/Strela/Controllers/WeatherForecastController.cs @@ -0,0 +1,26 @@ +using Microsoft.AspNetCore.Mvc; + +namespace Strela.Controllers +{ + [ApiController] + [Route("[controller]")] + public class WeatherForecastController : ControllerBase + { + private static readonly string[] Summaries = + [ + "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" + ]; + + [HttpGet(Name = "GetWeatherForecast")] + public IEnumerable Get() + { + return Enumerable.Range(1, 5).Select(index => new WeatherForecast + { + Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)), + TemperatureC = Random.Shared.Next(-20, 55), + Summary = Summaries[Random.Shared.Next(Summaries.Length)] + }) + .ToArray(); + } + } +} diff --git a/Strela/Program.cs b/Strela/Program.cs new file mode 100644 index 0000000..39ca0a3 --- /dev/null +++ b/Strela/Program.cs @@ -0,0 +1,35 @@ + +namespace Strela +{ + public class Program + { + public static void Main(string[] args) + { + var builder = WebApplication.CreateBuilder(args); + + // Add services to the container. + + builder.Services.AddControllers(); + // Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi + builder.Services.AddOpenApi(); + + var app = builder.Build(); + + // Configure the HTTP request pipeline. + if (app.Environment.IsDevelopment()) + { + app.UseSwagger(); + app.UseSwaggerUI(); + + } + + app.UseAuthorization(); + + + app.MapControllers(); + app.MapGet("/", () => "OK"); + + app.Run(); + } + } +} diff --git a/Strela/Properties/launchSettings.json b/Strela/Properties/launchSettings.json new file mode 100644 index 0000000..e6d1dec --- /dev/null +++ b/Strela/Properties/launchSettings.json @@ -0,0 +1,37 @@ +{ + "profiles": { + "http": { + "commandName": "Project", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "dotnetRunMessages": true, + "applicationUrl": "http://localhost:5294" + }, + "Container (.NET SDK)": { + "commandName": "SdkContainer", + "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}", + "environmentVariables": { + "ASPNETCORE_HTTP_PORTS": "8080" + }, + "publishAllPorts": true, + "useSSL": false + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + }, + "$schema": "https://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:53994/", + "sslPort": 44312 + } + } +} \ No newline at end of file diff --git a/Strela/Strela.csproj b/Strela/Strela.csproj new file mode 100644 index 0000000..75b99a9 --- /dev/null +++ b/Strela/Strela.csproj @@ -0,0 +1,18 @@ + + + + net10.0 + enable + enable + win-x64 + win-x64 + True + mcr.microsoft.com/dotnet/aspnet:10.0-nanoserver-ltsc2022 + + + + + + + + diff --git a/Strela/Strela.http b/Strela/Strela.http new file mode 100644 index 0000000..c9c464d --- /dev/null +++ b/Strela/Strela.http @@ -0,0 +1,6 @@ +@Strela_HostAddress = http://localhost:5294 + +GET {{Strela_HostAddress}}/weatherforecast/ +Accept: application/json + +### diff --git a/Strela/WeatherForecast.cs b/Strela/WeatherForecast.cs new file mode 100644 index 0000000..2cd6e5b --- /dev/null +++ b/Strela/WeatherForecast.cs @@ -0,0 +1,13 @@ +namespace Strela +{ + public class WeatherForecast + { + public DateOnly Date { get; set; } + + public int TemperatureC { get; set; } + + public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); + + public string? Summary { get; set; } + } +} diff --git a/Strela/appsettings.Development.json b/Strela/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/Strela/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/Strela/appsettings.json b/Strela/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/Strela/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/SwitchDahua/Form1.Designer.cs b/SwitchDahua/Form1.Designer.cs index 17d9791..e358035 100644 --- a/SwitchDahua/Form1.Designer.cs +++ b/SwitchDahua/Form1.Designer.cs @@ -78,7 +78,7 @@ // comboBox1 // comboBox1.FormattingEnabled = true; - comboBox1.Items.AddRange(new object[] { "172.16.48.9\tkr0-1-sw1", "172.16.48.10\tkr0-1-sw2", "172.16.48.11\tkr0-1-sw3", "172.16.48.12\tkr0-1-sw4", "172.16.48.13\tkr0-2-sw1", "172.16.48.14\tkr0-2-sw2", "172.16.48.15\tkr0-2-sw3", "172.16.48.16\tkr0-2-sw4", "172.16.48.17\tkr1_sw1", "172.16.48.18\tkr1_sw2", "172.16.48.19\tkr1_sw3", "172.16.48.20\tkr1_sw4", "172.16.48.21\tkr1_sw5", "172.16.48.22\tkr1_sw6", "172.16.48.23\tkr2-sw1", "172.16.48.24\tkr2-sw2", "172.16.48.25\tkr2-sw3", "172.16.48.26\tkr2-sw4", "172.16.48.27\tkr2-sw5", "172.16.48.28\tkr2-sw6", "172.16.48.29\tkr2-sw7", "172.16.48.30\tkr2-sw8", "172.16.48.31\tkr3-sw1", "172.16.48.32\tkr3-sw2", "172.16.48.33\tkr3-sw3", "172.16.48.34\tkr3-sw4", "172.16.48.35\tkr3-sw5", "172.16.48.36\tkr3-sw6", "172.16.48.37\tkr4-sw1", "172.16.48.38\tkr4-sw2", "172.16.48.39\tkr4-sw3", "172.16.48.40\tkr4-sw4", "172.16.48.41\tkr4-sw5", "172.16.48.42\tkr4-sw6", "172.16.48.43\tkr4-sw7", "172.16.48.44\tkr4-sw8", "172.16.48.45\tkr5-sw1", "172.16.48.46\tkr6-sw1", "172.16.48.47\tkr6-sw2", "172.16.48.48\tkr7-sw1", "172.16.48.49\tkr7-sw2", "172.16.48.50\tkr8-sw1", "172.16.48.51\tkr8-sw2", "172.16.48.52\tkr9-sw1", "172.16.48.53\tkr10-sw1", "172.16.48.54\tkr10-sw2", "172.16.48.55\tkr10-sw3", "172.16.48.56\tkr11-sw1", "172.16.48.57\tkr11-sw2", "172.16.48.58\tkr11-sw3", "172.16.48.59\tkr11-sw4", "172.16.48.60\tkr12-sw1", "172.16.48.61\tkr12-sw2", "172.16.48.62\tkr13-sw1", "172.16.48.63\tkr13-sw2", "172.16.48.64\tkr14-sw1", "172.16.48.65\tkr14-sw2", "172.16.48.66\tkr15-sw1", "172.16.48.67\tkr15-sw2", "172.16.48.68\tkr15-sw3", "172.16.48.69\tkr15-sw4", "172.16.48.70\tkr16-sw1", "172.16.48.71\tkr16-sw2", "172.16.48.72\tkr16-sw3", "172.16.48.73\tkr16-sw4", "172.16.48.74\tkr16-sw5", "172.16.48.75\tkr16-sw6", "172.16.48.76\tkr2_sw9", "172.16.48.77\tsw_rum111", "172.16.48.78\tkr15_sw5" }); + comboBox1.Items.AddRange(new object[] { "172.22.10.2\t", "172.22.10.3\t", "172.22.10.6\t", "172.22.10.7\t", "172.22.10.8\t", "172.22.10.9\t", "172.22.10.12\t", "172.22.10.13\t" }); comboBox1.Location = new Point(32, 20); comboBox1.Name = "comboBox1"; comboBox1.Size = new Size(147, 21); diff --git a/SwitchDahua/Form1.cs b/SwitchDahua/Form1.cs index 8be5d0e..dbac227 100644 --- a/SwitchDahua/Form1.cs +++ b/SwitchDahua/Form1.cs @@ -19,7 +19,7 @@ namespace SwitchDahua { ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => true }; - server = "172.16.48.9"; + server = "172.22.10.7"; _httpClient = new HttpClient(handler); _httpClient.Timeout = TimeSpan.FromSeconds(30); @@ -193,9 +193,10 @@ namespace SwitchDahua var responseJson = await response.Content.ReadAsStringAsync(); LLDP ListDev = JsonConvert.DeserializeObject(responseJson); - + var DevList = ListDev.Params; + DevList = DevList.OrderBy(item => item.ManagerIP).ToList(); string txt = string.Empty; - foreach (var dev in ListDev.Params) + foreach (var dev in DevList) { txt += dev.LocalInterface.Substring(dev.LocalInterface.LastIndexOf('/') + 1) + "\t" + dev.ManagerIP + Environment.NewLine; } diff --git a/Wiking/Wiking.csproj b/Wiking/Wiking.csproj index 3caa2cb..9828522 100644 --- a/Wiking/Wiking.csproj +++ b/Wiking/Wiking.csproj @@ -7,7 +7,7 @@ - + diff --git a/getSwitch/Program.cs b/getSwitch/Program.cs new file mode 100644 index 0000000..f73f07a --- /dev/null +++ b/getSwitch/Program.cs @@ -0,0 +1,69 @@ +using Renci.SshNet; + +namespace getSwitch +{ + internal class Program + { + static void Main(string[] args) + { + Dictionary listSw = new Dictionary + { + {"GE1/0/1", "kr1_sw1"},{"GE1/0/2", "kr1_sw2"},{"GE1/0/3", "kr1_sw3"},{"GE1/0/4", "kr1_sw4"}, + {"GE1/0/5", "kr1_sw5"},{"GE1/0/6", "kr1_sw6"},{"GE1/0/7", "kr2_sw1"},{"GE1/0/8", "kr2_sw2"}, + {"GE1/0/9", "kr2_sw3"},{"GE1/0/10", "kr2_sw4"},{"GE1/0/11", "kr2_sw5"},{"GE1/0/12", "kr2_sw6"}, + {"GE1/0/13", "kr2_sw7"},{"GE1/0/14", "kr2_sw8"},{"GE1/0/15", "kr2_sw9"},{"GE1/0/16", "kr3_sw2"}, + {"GE1/0/17", "kr3_sw1"},{"GE1/0/18", "kr3_sw3"},{"GE1/0/19", "kr3_sw4"},{"GE1/0/20", "kr3_sw5"}, + {"GE1/0/21", "kr3_sw6"},{"GE1/0/22", "kr4_sw1"},{"GE1/0/23", "kr4_sw2"},{"GE1/0/24", "kr4_sw3"}, + {"GE2/0/1", "kr4_sw4"},{"GE2/0/2", "kr4_sw5"},{"GE2/0/3", "kr4_sw6"},{"GE2/0/4", "kr4_sw7"}, + {"GE2/0/5", "kr4_sw8"},{"GE2/0/6", "kr5_sw1"},{"GE2/0/7", "kr6_sw1"},{"GE2/0/8", "kr6_sw2"}, + {"GE2/0/9", "kr7_sw1"},{"GE2/0/10", "kr7_sw2"},{"GE2/0/11", "kr8_sw1"},{"GE2/0/12", "kr8_sw2"}, + {"GE2/0/13", "kr9_sw1"},{"GE2/0/14", "kr10_sw1"},{"GE2/0/15", "kr10_sw2"},{"GE2/0/16", "kr10_sw3"}, + {"GE2/0/17", "kr11_sw1"},{"GE2/0/18", "kr11_sw2"},{"GE2/0/19", "kr11_sw3"},{"GE2/0/20", "kr11_sw4"}, + {"GE2/0/21", "kr12_sw1"},{"GE2/0/22", "kr12_sw2"},{"GE2/0/23", "kr13_sw1"},{"GE2/0/24", "kr14_sw1"}, + {"GE3/0/1", "kr14_sw2"},{"GE3/0/2", "kr13_sw2"},{"GE3/0/3", "kr15_sw1"},{"GE3/0/4", "kr15_sw3"},{"GE3/0/5", "kr15_sw2"}, + {"GE3/0/6", "kr15_sw4"},{"GE3/0/7", "kr15_sw5"},{"GE3/0/8", "kr16_sw1"},{"GE3/0/9", "kr16_sw2"},{"GE3/0/10", "kr16_sw3"}, + {"GE3/0/11", "kr16_sw4"},{"GE3/0/12", "kr16_sw5"},{"GE3/0/13", "kr16_sw6"},{"GE3/0/14", "kr0_1_sw1"},{"GE3/0/15", "kr0_1_sw2"}, + {"GE3/0/16", "kr0_1_sw3"},{"GE3/0/17", "kr0_1_sw4"},{"GE3/0/18", "kr00_2_sw1"},{"GE3/0/19", "kr00_2_sw2"},{"GE3/0/20", "kr00_2_sw3"},{"GE3/0/21", "kr0_2_sw4"} + }; + + string host = "172.16.48.4"; + string username = "admin"; + string password = "4NUDZhJ789"; + int port = 22; // стандартный порт SSH +#if DEBUG + args = new string[] { "9BBB" }; +#endif + + using (var client = new SshClient(host, port, username, password)) + { + try + { + // Подключаемся + client.Connect(); + //Console.WriteLine("Подключение установлено!"); + + + var command = client.RunCommand($"show mac-address | include {args[0]}"); + var otvet = command.Result; + otvet = otvet.Split("\r\n")[1]; + otvet = otvet.Substring(45, 8); + Console.WriteLine(listSw[otvet]); + + //Console.ReadKey(); + } + catch (Exception ex) + { + Console.WriteLine($"Ошибка: {ex.Message}"); + } + finally + { + if (client.IsConnected) + { + client.Disconnect(); + // Console.WriteLine("Отключено."); + } + } + } + } + } +} diff --git a/getSwitch/getSwitch.csproj b/getSwitch/getSwitch.csproj new file mode 100644 index 0000000..df43790 --- /dev/null +++ b/getSwitch/getSwitch.csproj @@ -0,0 +1,14 @@ + + + + Exe + net8.0 + enable + enable + + + + + + + diff --git a/lsConsole/Program.cs b/lsConsole/Program.cs index 3241338..f9afa42 100644 --- a/lsConsole/Program.cs +++ b/lsConsole/Program.cs @@ -75,15 +75,7 @@ Dictionary listSw = new Dictionary }; List listMac = new List() { -"2959", -"5c09", -"2827", -"84e8", -"848d", -"8413", -"88a0", -"0db0", -"8b4e" +"b13b" }; string host = "172.16.48.4"; diff --git a/lsConsole/lsConsole.csproj b/lsConsole/lsConsole.csproj index 5dbcbaf..c8ba30d 100644 --- a/lsConsole/lsConsole.csproj +++ b/lsConsole/lsConsole.csproj @@ -2,7 +2,7 @@ Exe - net10.0 + net9.0 enable enable diff --git a/lsSoft.slnx b/lsSoft.slnx index ffe7fd7..8b6eb8b 100644 --- a/lsSoft.slnx +++ b/lsSoft.slnx @@ -1,17 +1,27 @@ + + + + + + + + + + - - + + diff --git a/snmp_dahua/Program.cs b/snmp_dahua/Program.cs new file mode 100644 index 0000000..5d2390c --- /dev/null +++ b/snmp_dahua/Program.cs @@ -0,0 +1,40 @@ +namespace snmp_dahua +{ + using System.Net; + using System.Net.NetworkInformation; + internal class Program + { + static async Task Main(string[] args) + { +#if DEBUG + args = new string[2]; + args[0] = "172.16.50.14"; +#endif + + string baseUrlS = $"http://{args[0]}"; + var credCacheS = new CredentialCache(); + credCacheS.Add(new Uri(baseUrlS), "Digest", new NetworkCredential("admin", "4NUDZhJ7")); + using (var handler = new HttpClientHandler + { + Credentials = credCacheS, + ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => true + }) + using (var httpClient = new HttpClient(handler)) + { + string requestUrl = $"{baseUrlS}/cgi-bin/configManager.cgi?action=setConfig&SNMP.Enable=false"; + var response = await httpClient.GetAsync(requestUrl); + response.EnsureSuccessStatusCode(); + var r = response.ReasonPhrase;// .Content.ReadAsStringAsync(); + if (r.StartsWith("OK")) + { + string requestUrl2 = $"{baseUrlS}/cgi-bin/configManager.cgi?action=setConfig&SNMP.Enable=true"; + var response2 = await httpClient.GetAsync(requestUrl2); + var r2 = response2.ReasonPhrase;//.Content.ReadAsStringAsync(); + if (r2.StartsWith("OK")) Console.WriteLine("0"); + else Console.WriteLine("1"); + } + else Console.WriteLine("1"); + } + } + } +} diff --git a/snmp_dahua/snmp_dahua.csproj b/snmp_dahua/snmp_dahua.csproj new file mode 100644 index 0000000..2150e37 --- /dev/null +++ b/snmp_dahua/snmp_dahua.csproj @@ -0,0 +1,10 @@ + + + + Exe + net8.0 + enable + enable + + + diff --git a/sync_time_dh/Program.cs b/sync_time_dh/Program.cs new file mode 100644 index 0000000..21b14ef --- /dev/null +++ b/sync_time_dh/Program.cs @@ -0,0 +1,51 @@ +using System.Net; + +namespace sync_time_dh +{ + internal class Program + { + static async Task Main(string[] args) + { +#if DEBUG + args = new string[1]; + args[0] = "172.16.54.30"; +#endif + string baseUrlU = $"http://{args[0]}"; + var credCacheU = new CredentialCache(); + credCacheU.Add(new Uri(baseUrlU), "Digest", new NetworkCredential("admin", "4NUDZhJ7")); + using (var handler = new HttpClientHandler + { + Credentials = credCacheU, + ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => true + }) + using (var httpClient = new HttpClient(handler)) + { + string requestUrl1 = $"{baseUrlU}/cgi-bin/global.cgi?action=setCurrentTime&time={DateTime.Now:yyyy-MM-dd HH:mm:ss}"; + string requestUrl2 = $"{baseUrlU}/cgi-bin/configManager.cgi?action=setConfig&NTP.Enable=false&NTP.TimeZone=3&NTP.TimeZoneDesc=Moscow"; + string requestUrl3 = $"{baseUrlU}/cgi-bin/configManager.cgi?action=setConfig&Locales.TimeFormat=dd-MM-yyyy HH:mm:ss"; + var response1 = await httpClient.GetAsync(requestUrl1); + var response2 = await httpClient.GetAsync(requestUrl2); + var response3 = await httpClient.GetAsync(requestUrl3); + try + { + response1.EnsureSuccessStatusCode(); + response2.EnsureSuccessStatusCode(); + response3.EnsureSuccessStatusCode(); + } + catch (Exception) + { + Console.WriteLine("1"); + return; + } + var r1 = await response1.Content.ReadAsStringAsync(); + var r2 = await response2.Content.ReadAsStringAsync(); + var r3 = await response3.Content.ReadAsStringAsync(); + if (r1.StartsWith("OK") && r2.StartsWith("OK") && r3.StartsWith("OK")) + { + Console.WriteLine("0"); + } + else Console.WriteLine("1"); + } + } + } +} diff --git a/sync_time_dh/sync_time_dh.csproj b/sync_time_dh/sync_time_dh.csproj new file mode 100644 index 0000000..2150e37 --- /dev/null +++ b/sync_time_dh/sync_time_dh.csproj @@ -0,0 +1,10 @@ + + + + Exe + net8.0 + enable + enable + + + diff --git a/sync_time_hik/Program.cs b/sync_time_hik/Program.cs new file mode 100644 index 0000000..5cbee4f --- /dev/null +++ b/sync_time_hik/Program.cs @@ -0,0 +1,46 @@ +using System.Net; +using System.Text; + +namespace sync_time_hik +{ + internal class Program + { + static async Task Main(string[] args) + { +#if DEBUG + args = new string[1]; + args[0] = "172.16.50.13"; +#endif + string baseUrlU = $"http://{args[0]}"; + var credCacheU = new CredentialCache(); + credCacheU.Add(new Uri(baseUrlU), "Digest", new NetworkCredential("admin", "4NUDZhJ7")); + using (var handler = new HttpClientHandler + { + Credentials = credCacheU, + ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => true + }) + using (var httpClient = new HttpClient(handler)) + { + string requestUrl = $"{baseUrlU}/ISAPI/System/time"; + + string xmlBody = $@""; + + // Создаем контент для PUT запроса + var content = new StringContent(xmlBody, Encoding.UTF8, "application/xml"); + + // Выполняем PUT запрос + var response = await httpClient.PutAsync(requestUrl, content); + response.EnsureSuccessStatusCode(); + var r = response.ReasonPhrase; + if (r.StartsWith("OK")) + { + Console.WriteLine("0"); + } + else Console.WriteLine("1"); + } +#if DEBUG + Console.ReadKey(); +#endif + } + } +} diff --git a/sync_time_hik/sync_time_hik.csproj b/sync_time_hik/sync_time_hik.csproj new file mode 100644 index 0000000..2150e37 --- /dev/null +++ b/sync_time_hik/sync_time_hik.csproj @@ -0,0 +1,10 @@ + + + + Exe + net8.0 + enable + enable + + + diff --git a/workload-install.ps1 b/workload-install.ps1 new file mode 100644 index 0000000..271841b --- /dev/null +++ b/workload-install.ps1 @@ -0,0 +1,332 @@ +# +# Copyright (c) Samsung Electronics. All rights reserved. +# Licensed under the MIT license. See LICENSE file in the project root for full license information. +# + +<# +.SYNOPSIS +Installs Tizen workload manifest. +.DESCRIPTION +Installs the WorkloadManifest.json and WorkloadManifest.targets files for Tizen to the dotnet sdk. +.PARAMETER Version +Use specific VERSION +.PARAMETER DotnetInstallDir +Dotnet SDK Location installed +#> + +[cmdletbinding()] +param( + [Alias('v')][string]$Version="", + [Alias('d')][string]$DotnetInstallDir="", + [Alias('t')][string]$DotnetTargetVersionBand="", + [Alias('u')][switch]$UpdateAllWorkloads +) + +Set-StrictMode -Version Latest +$ErrorActionPreference = "Stop" +$ProgressPreference = "SilentlyContinue" + +$ManifestBaseName = "Samsung.NET.Sdk.Tizen.Manifest" +$global:FallbackId = "" + +$LatestVersionMap = [ordered]@{ + "$ManifestBaseName-6.0.100" = "7.0.101"; + "$ManifestBaseName-6.0.200" = "7.0.100-preview.13.6"; + "$ManifestBaseName-6.0.300" = "8.0.133"; + "$ManifestBaseName-6.0.400" = "9.0.104"; + "$ManifestBaseName-7.0.100-preview.6" = "7.0.100-preview.6.14"; + "$ManifestBaseName-7.0.100-preview.7" = "7.0.100-preview.7.20"; + "$ManifestBaseName-7.0.100-rc.1" = "7.0.100-rc.1.22"; + "$ManifestBaseName-7.0.100-rc.2" = "7.0.100-rc.2.24"; + "$ManifestBaseName-7.0.100" = "7.0.103"; + "$ManifestBaseName-7.0.200" = "7.0.105"; + "$ManifestBaseName-7.0.300" = "7.0.120"; + "$ManifestBaseName-7.0.400" = "10.0.106"; + "$ManifestBaseName-8.0.100-alpha.1" = "7.0.104"; + "$ManifestBaseName-8.0.100-preview.2" = "7.0.106"; + "$ManifestBaseName-8.0.100-preview.3" = "7.0.107"; + "$ManifestBaseName-8.0.100-preview.4" = "7.0.108"; + "$ManifestBaseName-8.0.100-preview.5" = "7.0.110"; + "$ManifestBaseName-8.0.100-preview.6" = "7.0.121"; + "$ManifestBaseName-8.0.100-preview.7" = "7.0.122"; + "$ManifestBaseName-8.0.100-rc.1" = "7.0.124"; + "$ManifestBaseName-8.0.100-rc.2" = "7.0.125"; + "$ManifestBaseName-8.0.100-rtm" = "7.0.127"; + "$ManifestBaseName-8.0.100" = "8.0.144"; + "$ManifestBaseName-8.0.200" = "8.0.157"; + "$ManifestBaseName-8.0.300" = "8.0.156"; + "$ManifestBaseName-8.0.400" = "10.0.109"; + "$ManifestBaseName-9.0.100-alpha.1" = "8.0.134"; + "$ManifestBaseName-9.0.100-preview.1" = "8.0.135"; + "$ManifestBaseName-9.0.100-preview.2" = "8.0.137"; + "$ManifestBaseName-9.0.100" = "10.0.104"; + "$ManifestBaseName-9.0.200" = "10.0.110"; + "$ManifestBaseName-9.0.300" = "10.0.111"; +} + +function New-TemporaryDirectory { + $parent = [System.IO.Path]::GetTempPath() + $name = [System.IO.Path]::GetRandomFileName() + New-Item -ItemType Directory -Path (Join-Path $parent $name) +} + +function Ensure-Directory([string]$TestDir) { + Try { + New-Item -ItemType Directory -Path $TestDir -Force -ErrorAction stop | Out-Null + [io.file]::OpenWrite($(Join-Path -Path $TestDir -ChildPath ".test-write-access")).Close() + Remove-Item -Path $(Join-Path -Path $TestDir -ChildPath ".test-write-access") -Force + } + Catch [System.UnauthorizedAccessException] { + Write-Error "No permission to install. Try run with administrator mode." + } +} + +function Get-LatestVersion([string]$Id) { + $attempts=3 + $sleepInSeconds=3 + do + { + try + { + $Response = Invoke-WebRequest -Uri https://api.nuget.org/v3-flatcontainer/$($Id.ToLowerInvariant())/index.json -UseBasicParsing | ConvertFrom-Json + return $Response.versions | Select-Object -Last 1 + } + catch { + Write-Host "Id: $Id" + Write-Host "An exception was caught: $($_.Exception.Message)" + } + + $attempts-- + if ($attempts -gt 0) { Start-Sleep $sleepInSeconds } + } while ($attempts -gt 0) + + if ($LatestVersionMap.Contains($Id)) + { + Write-Host "Return cached latest version." + return $LatestVersionMap.$Id + } + else + { + $SubStringId = $Id.Substring(0, $ManifestBaseName.Length + 2); + $MatchingFallbackId = @() + $MatchingFallbackVersion = @() + foreach ($key in $LatestVersionMap.Keys) { + if ($key -like "$SubStringId*") { + $MatchingFallbackId += $key + $MatchingFallbackVersion += $LatestVersionMap[$key] + } + } + if ($MatchingFallbackVersion) + { + $global:FallbackId = $MatchingFallbackId[-1] + $FallbackVersion = $MatchingFallbackVersion[-1] + Write-Host "Return fallback version: $FallbackVersion" + return $FallbackVersion + } + } + + Write-Error "Wrong Id: $Id" +} + +function Get-Package([string]$Id, [string]$Version, [string]$Destination, [string]$FileExt = "nupkg") { + $OutFileName = "$Id.$Version.$FileExt" + $OutFilePath = Join-Path -Path $Destination -ChildPath $OutFileName + + if ($Id -match ".net[0-9]+$") { + $Id = $Id -replace (".net[0-9]+", "") + } + + Invoke-WebRequest -Uri "https://www.nuget.org/api/v2/package/$Id/$Version" -OutFile $OutFilePath + + return $OutFilePath +} + +function Install-Pack([string]$Id, [string]$Version, [string]$Kind) { + $TempZipFile = $(Get-Package -Id $Id -Version $Version -Destination $TempDir -FileExt "zip") + $TempUnzipDir = Join-Path -Path $TempDir -ChildPath "unzipped\$Id" + + switch ($Kind) { + "manifest" { + Expand-Archive -Path $TempZipFile -DestinationPath $TempUnzipDir + New-Item -Path $TizenManifestDir -ItemType "directory" -Force | Out-Null + Copy-Item -Path "$TempUnzipDir\data\*" -Destination $TizenManifestDir -Force + } + {($_ -eq "sdk") -or ($_ -eq "framework")} { + Expand-Archive -Path $TempZipFile -DestinationPath $TempUnzipDir + if ( ($kind -eq "sdk") -and ($Id -match ".net[0-9]+$")) { + $Id = $Id -replace (".net[0-9]+", "") + } + $TargetDirectory = $(Join-Path -Path $DotnetInstallDir -ChildPath "packs\$Id\$Version") + New-Item -Path $TargetDirectory -ItemType "directory" -Force | Out-Null + Copy-Item -Path "$TempUnzipDir/*" -Destination $TargetDirectory -Recurse -Force + } + "template" { + $TargetFileName = "$Id.$Version.nupkg".ToLower() + $TargetDirectory = $(Join-Path -Path $DotnetInstallDir -ChildPath "template-packs") + New-Item -Path $TargetDirectory -ItemType "directory" -Force | Out-Null + Copy-Item $TempZipFile -Destination $(Join-Path -Path $TargetDirectory -ChildPath "$TargetFileName") -Force + } + } +} + +function Remove-Pack([string]$Id, [string]$Version, [string]$Kind) { + switch ($Kind) { + "manifest" { + Remove-Item -Path $TizenManifestDir -Recurse -Force + } + {($_ -eq "sdk") -or ($_ -eq "framework")} { + $TargetDirectory = $(Join-Path -Path $DotnetInstallDir -ChildPath "packs\$Id\$Version") + Remove-Item -Path $TargetDirectory -Recurse -Force + } + "template" { + $TargetFileName = "$Id.$Version.nupkg".ToLower(); + Remove-Item -Path $(Join-Path -Path $DotnetInstallDir -ChildPath "template-packs\$TargetFileName") -Force + } + } +} + +function Install-TizenWorkload([string]$DotnetVersion) +{ + $VersionSplitSymbol = '.' + $SplitVersion = $DotnetVersion.Split($VersionSplitSymbol) + + $CurrentDotnetVersion = [Version]"$($SplitVersion[0]).$($SplitVersion[1])" + $DotnetVersionBand = $SplitVersion[0] + $VersionSplitSymbol + $SplitVersion[1] + $VersionSplitSymbol + $SplitVersion[2][0] + "00" + $ManifestName = "$ManifestBaseName-$DotnetVersionBand" + + if ($DotnetTargetVersionBand -eq "" -or $UpdateAllWorkloads.IsPresent) { + if ($CurrentDotnetVersion -ge "7.0") + { + $IsPreviewVersion = $DotnetVersion.Contains("-preview") -or $DotnetVersion.Contains("-rc") -or $DotnetVersion.Contains("-alpha") + if ($IsPreviewVersion -and ($SplitVersion.Count -ge 4)) { + $DotnetTargetVersionBand = $DotnetVersionBand + $SplitVersion[2].SubString(3) + $VersionSplitSymbol + $($SplitVersion[3]) + $ManifestName = "$ManifestBaseName-$DotnetTargetVersionBand" + } + elseif ($DotnetVersion.Contains("-rtm") -and ($SplitVersion.Count -ge 3)) { + $DotnetTargetVersionBand = $DotnetVersionBand + $SplitVersion[2].SubString(3) + $ManifestName = "$ManifestBaseName-$DotnetTargetVersionBand" + } + else { + $DotnetTargetVersionBand = $DotnetVersionBand + } + } + else { + $DotnetTargetVersionBand = $DotnetVersionBand + } + } + + # Check latest version of manifest. + if ($Version -eq "" -or $UpdateAllWorkloads.IsPresent) { + $Version = Get-LatestVersion -Id $ManifestName + } + + # Check workload manifest directory. + $ManifestDir = Join-Path -Path $DotnetInstallDir -ChildPath "sdk-manifests" | Join-Path -ChildPath $DotnetTargetVersionBand + $TizenManifestDir = Join-Path -Path $ManifestDir -ChildPath "samsung.net.sdk.tizen" + $TizenManifestFile = Join-Path -Path $TizenManifestDir -ChildPath "WorkloadManifest.json" + + # Check and remove already installed old version. + if (Test-Path $TizenManifestFile) { + $ManifestJson = $(Get-Content $TizenManifestFile | ConvertFrom-Json) + $OldVersion = $ManifestJson.version + if ($OldVersion -eq $Version) { + $DotnetWorkloadList = Invoke-Expression "& '$DotnetCommand' workload list | Select-String -Pattern '^tizen'" + if ($DotnetWorkloadList) + { + Write-Host "Tizen Workload $Version version is already installed." + Continue + } + } + + Ensure-Directory $ManifestDir + Write-Host "Removing $ManifestName/$OldVersion from $ManifestDir..." + Remove-Pack -Id $ManifestName -Version $OldVersion -Kind "manifest" + $ManifestJson.packs.PSObject.Properties | ForEach-Object { + Write-Host "Removing $($_.Name)/$($_.Value.version)..." + Remove-Pack -Id $_.Name -Version $_.Value.version -Kind $_.Value.kind + } + } + + Ensure-Directory $ManifestDir + $TempDir = $(New-TemporaryDirectory) + + # Install workload manifest. + Write-Host "Installing $ManifestName/$Version to $ManifestDir..." + if ($global:FallbackId) { + Install-Pack -Id $global:FallbackId -Version $Version -Kind "manifest" + } else { + Install-Pack -Id $ManifestName -Version $Version -Kind "manifest" + } + + # Download and install workload packs. + $NewManifestJson = $(Get-Content $TizenManifestFile | ConvertFrom-Json) + $NewManifestJson.packs.PSObject.Properties | ForEach-Object { + Write-Host "Installing $($_.Name)/$($_.Value.version)..." + Install-Pack -Id $_.Name -Version $_.Value.version -Kind $_.Value.kind + } + + # Add tizen to the installed workload metadata. + # Featured version band for metadata does NOT include any preview specifier. + # https://github.com/dotnet/sdk/blob/main/documentation/general/workloads/user-local-workloads.md + New-Item -Path $(Join-Path -Path $DotnetInstallDir -ChildPath "metadata\workloads\$DotnetVersionBand\InstalledWorkloads\tizen") -Force | Out-Null + if (Test-Path $(Join-Path -Path $DotnetInstallDir -ChildPath "metadata\workloads\$DotnetVersionBand\InstallerType\msi")) { + New-Item -Path "HKLM:\SOFTWARE\Microsoft\dotnet\InstalledWorkloads\Standalone\x64\$DotnetTargetVersionBand\tizen" -Force | Out-Null + } + + # Clean up + Remove-Item -Path $TempDir -Force -Recurse + + Write-Host "Done installing Tizen workload $Version" +} + +# Check dotnet install directory. +if ($DotnetInstallDir -eq "") { + if ($Env:DOTNET_ROOT -And $(Test-Path "$Env:DOTNET_ROOT")) { + $DotnetInstallDir = $Env:DOTNET_ROOT + } else { + $DotnetInstallDir = Join-Path -Path $Env:Programfiles -ChildPath "dotnet" + } +} +if (-Not $(Test-Path "$DotnetInstallDir")) { + Write-Error "No installed dotnet '$DotnetInstallDir'." +} + +# Check installed dotnet version +$DotnetCommand = "$DotnetInstallDir\dotnet" +if (Get-Command $DotnetCommand -ErrorAction SilentlyContinue) +{ + if ($UpdateAllWorkloads.IsPresent) + { + $InstalledDotnetSdks = Invoke-Expression "& '$DotnetCommand' --list-sdks | Select-String -Pattern '^6|^7'" | ForEach-Object {$_ -replace (" \[.*","")} + } + else + { + $InstalledDotnetSdks = Invoke-Expression "& '$DotnetCommand' --version" + } +} +else +{ + Write-Error "'$DotnetCommand' occurs an error." +} + +if (-Not $InstalledDotnetSdks) +{ + Write-Host "`n.NET SDK version 6 or later is required to install Tizen Workload." +} +else +{ + foreach ($DotnetSdk in $InstalledDotnetSdks) + { + try { + Write-Host "`nCheck Tizen Workload for sdk $DotnetSdk" + Install-TizenWorkload -DotnetVersion $DotnetSdk + } + catch { + Write-Host "Failed to install Tizen Workload for sdk $DotnetSdk" + Write-Host "$_" + Continue + } + } +} + +Write-Host "`nDone"