Exemplo n.º 1
0
        /// <summary>
        /// Occurs when disable hosts clicked.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The event arguments.
        /// </param>
        private void OnDisableHostsClick(object sender, EventArgs e)
        {
            bool checkState = (sender as dynamic).Checked;

            if (checkState)
            {
                HostsFile.EnableHostsFile();
            }
            else
            {
                HostsFile.DisableHostsFile();
            }

            this.UpdateHostsFileState();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Occurs when disable hosts clicked.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The event arguments.
        /// </param>
        private void OnDisableHostsClick(object sender, EventArgs e)
        {
            bool checkState = (sender as dynamic).Checked;

            this.menuDisable.Checked   = !checkState;
            this.buttonDisable.Checked = !checkState;

            if (checkState)
            {
                HostsFile.EnableHostsFile();
            }
            else
            {
                HostsFile.DisableHostsFile();
            }
        }
Exemplo n.º 3
0
        private void NewEntry(HostsFile hostsFile)
        {
            Console.Clear();
            Console.WriteLine("Please enter the URL you wish to map.");
            Regex regex = new Regex(@"(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()!@:%_\+.~#?&\/\/=]*)");

            string URLInput = Console.ReadLine();

            if (regex.IsMatch(URLInput))
            {
                Console.WriteLine("valid URL");
            }
            else
            {
                Console.WriteLine("Invalid URL. Press any key to return to main menu.");
                Console.ReadKey();
                Main(hostsFile);
            }

            Console.WriteLine($"Please enter the IP you wish to map {URLInput} to.");
            regex = new Regex(@"((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}|localhost)");

            string IPInput = Console.ReadLine();

            if (regex.IsMatch(IPInput))
            {
                Console.WriteLine("valid IP");
                HostsEntry newEntry = new HostsEntry(URLInput, IPInput);
                hostsFile.hostsEntries.Add(newEntry);
                hostsFile.SaveHostsFile();
                Main(hostsFile);
            }
            else
            {
                Console.WriteLine("Invalid IP. Press any key to return to main menu.");
                Console.ReadKey();
                Main(hostsFile);
            }
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            HostsFile hostsFile = new HostsFile();
            MainMenu  mainMenu  = new MainMenu();

            mainMenu.Main(hostsFile);



            //switch (Console.ReadKey().Key)
            //{
            //    case ConsoleKey.D0:
            //        EntryDetails(hostsFile.hostsEntries[0], args);
            //        break;
            //    case ConsoleKey.D1:
            //        EntryDetails(hostsFile.hostsEntries[1], args);
            //        break;
            //    case ConsoleKey.D2:
            //        EntryDetails(hostsFile.hostsEntries[2], args);
            //        break;
            //    case ConsoleKey.D3:
            //        EntryDetails(hostsFile.hostsEntries[3], args);
            //        break;
            //    case ConsoleKey.D4:
            //        EntryDetails(hostsFile.hostsEntries[4], args);
            //        break;
            //    case ConsoleKey.D5:
            //        EntryDetails(hostsFile.hostsEntries[5], args);
            //        break;
            //    case ConsoleKey.N:
            //        Console.WriteLine('N');
            //        break;
            //    default:
            //        Console.WriteLine("invalid key");
            //        break;
            //}
        }
Exemplo n.º 5
0
        internal void Main(HostsFile hostsFile)
        {
            //int pages = hostsFile.hostsEntries.Count
            int pages = (int)(MathF.Ceiling((float)(((hostsFile.hostsEntries.Count - 1) / 8))));

            Console.Clear();
            hosts = hostsFile;

            Console.WriteLine("Hosts file currently contains these entries:");
            Console.WriteLine("\n");
            Console.WriteLine($"Page {page + 1}");
            Console.WriteLine("\n");

            if (page > 0)
            {
                Console.WriteLine($"1. Previous Page");
            }

            for (int i = 0; i <= 7; i++)
            {
                int actualEntry = i + (8 * page);
                if (actualEntry < hostsFile.hostsEntries.Count)
                {
                    Console.WriteLine($"{i + 2}. {hostsFile.hostsEntries[actualEntry].URL} mapped to {hostsFile.hostsEntries[actualEntry].IP}.");
                }
            }
            if (pages > page)
            {
                Console.WriteLine($"0. Next Page");
            }
            //}
            Console.WriteLine("\n");
            Console.WriteLine("Press a number for more actions, \"B\" to backup, \"N\" for a new entry, or \"E\" to exit.");
            string input = Console.ReadKey().KeyChar.ToString();

            if (input == "E" || input == "e")
            {
                Console.Clear();
                Console.Write("Are you sure you wish to exit? (Y/N)");
                switch (Console.ReadKey().Key)
                {
                case ConsoleKey.Y:
                    Environment.Exit(0);
                    break;

                case ConsoleKey.N:
                    Main(hostsFile);
                    break;
                }
            }
            if (input == "0")
            {
                if (pages > page)
                {
                    page++;
                }
                Main(hostsFile);
            }

            if (input == "1")
            {
                if (page > 0)
                {
                    page--;
                }
                Main(hostsFile);
            }

            if (int.TryParse(input, out int parsedInput))
            {
                int pageCorrectedInput = parsedInput - 2 + (page * 8);
                if (pageCorrectedInput < hostsFile.hostsEntries.Count && parsedInput != -1)
                {
                    EntryDetails(hostsFile.hostsEntries[pageCorrectedInput]);
                }
                else
                {
                    Main(hostsFile);
                }
            }
            else if (input == "N" || input == "n")
            {
                NewEntry(hostsFile);
            }
            else if (input == "B" || input == "b")
            {
                hosts.BackupHostsFile();
                Console.Clear();
                Console.WriteLine($"Backup made at {HostsFile.HostsFilePath}.bkup.\nPress any key to continue.");
                Console.ReadKey();
                Main(hostsFile);
            }
            else
            {
                Main(hostsFile);
            }
        }