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&SNMP.ReadCommon=public&SNMP.WriteCommon=private&SNMP.V2Enable=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&SNMP.ReadCommon=public&SNMP.WriteCommon=private&SNMP.V2Enable=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");
            }
        }
    }
}
