Esempio n. 1
0
File: p2t.cs Progetto: vsoul-km/p2t
        private static void Result()
        {
            WriteLog writeLog = new WriteLog(false);
            Telegram telegram = new Telegram(CommandLineArguments.TelegramBotToken, CommandLineArguments.TelegramChatId);

            Console.WriteLine();
            writeLog.Append("");

            if (Statistic.PingSuccess == 0 && Statistic.PingLost == 0 && Statistic.TraceRoutes == 0)
            {
                string textAllLost = "Packets: sent - 0; Lost - 0%; Traceroutes: 0; Avg.RTT: -- ms; Unique IP addresses: 0;";
                Console.WriteLine(textAllLost);
                if (CommandLineArguments.LogEnabled)
                {
                    writeLog.Append(textAllLost);
                }

                if (CommandLineArguments.TelegramSendAll || CommandLineArguments.TelegramSendErrors)
                {
                    telegram.SendMessage(textAllLost);
                }
                return;
            }

            if (Statistic.PingSuccess == 0 && Statistic.TraceRoutes != 0)
            {
                string textTraceroutesOnly = $"Packets: sent - {Statistic.PingLost}; Lost - 100%; Traceroutes: {Statistic.TraceRoutes}; Avg.RTT: -- ms; Unique IP addresses: 0;";
                Console.WriteLine(textTraceroutesOnly);
                writeLog.Append(textTraceroutesOnly);

                if (CommandLineArguments.TelegramSendAll || CommandLineArguments.TelegramSendErrors)
                {
                    telegram.SendMessage(textTraceroutesOnly);
                }

                return;
            }

            if (Statistic.PingSuccess == 0 && Statistic.PingLost != 0 && Statistic.TraceRoutes == 0)
            {
                string textLostOnly = $"Packets: sent - {Statistic.PingLost}, lost - 100%; Traceroutes: 0; Avg.RTT: -- ms; Unique IP addresses: 0;";
                Console.WriteLine(textLostOnly);
                writeLog.Append(textLostOnly);

                if (CommandLineArguments.TelegramSendAll || CommandLineArguments.TelegramSendErrors)
                {
                    telegram.SendMessage(textLostOnly);
                }

                return;
            }

            string textOther = $"Packets: sent - {Statistic.PingSuccess + Statistic.PingLost}; Lost - {Statistic.PingLost} ({(Statistic.PingLost * 100) / (Statistic.PingSuccess + Statistic.PingLost)}%); Traceroutes: {Statistic.TraceRoutes}; Avg.RTT: {Statistic.RttSumm / Statistic.PingSuccess} ms; Unique IP addresses: {Statistic.GetIp.Count}";

            Console.WriteLine(textOther);
            writeLog.Append(textOther);

            if (CommandLineArguments.TelegramSendAll || CommandLineArguments.TelegramSendErrors)
            {
                telegram.SendMessage(textOther);
            }

            if (CommandLineArguments.FollowTheName)
            {
                string footerText = "";
                footerText += "Used IP addresses: ";

                foreach (string ipAddress in Statistic.GetIp)
                {
                    footerText += ipAddress + " ";
                }

                Console.WriteLine(footerText);
                writeLog.Append(footerText);

                if (CommandLineArguments.TelegramSendAll || CommandLineArguments.TelegramSendErrors)
                {
                    telegram.SendMessage(footerText);
                }
            }
        }