Пример #1
0
        public static async Task <PiholeInfo> GetStatsAsync(string piholeIpAddress)
        {
            string piholeJsonResponse = await GetPiholeJsonAsync(piholeIpAddress);

            PiholeInfo piholeStats = JsonSerializer.Deserialize <PiholeInfo>(piholeJsonResponse);

            return(piholeStats);
        }
Пример #2
0
        public static void PrintStats(PiholeInfo piholeStats)
        {
            string output = $"Pihole Stats (Today): \n \n";

            output += $"Status: { piholeStats.Status } \n";
            output += $"DNS Queries: { piholeStats.DnsQueriesToday } \n";
            output += $"Ads Blocked: { piholeStats.AdsBlockedToday} \n";
            output += $"% Blocked: { Math.Round(piholeStats.PercentBlockedToday, 2) } \n";
            output += $"Queries Forwarded: { piholeStats.QueriesForwarded } \n";
            output += $"Queries Cached: { piholeStats.QueriesCached } \n";

            Console.WriteLine(output);
        }
Пример #3
0
        static async Task Main(string[] args)
        {
            string piholeIp;

            bool repeat;

            do
            {
                repeat = true;

                Console.WriteLine("Enter the PiHole IPv4 address (e.g. 192.168.1.1):");

                piholeIp = Console.ReadLine();

                bool ipIsValid = Validator.IpAddressIsValid(piholeIp);
                if (ipIsValid)
                {
                    break;
                }
                else
                {
                    Console.WriteLine("That's not a valid IPv4 address..");
                    Console.WriteLine();
                }
            } while (repeat == true);

            Console.WriteLine();
            Console.WriteLine($"Contacting pihole at: { piholeIp }...");

            Thread.Sleep(500);

            Console.WriteLine();

            PiholeInfo piholeStats = await PiholeService.GetStatsAsync(piholeIp);

            PiholeService.PrintStats(piholeStats);
        }