This commit is contained in:
@@ -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<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/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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="listCam.csv">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -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
|
||||
|
Reference in New Issue
Block a user