Exemple #1
0
        public static void RemoveHostsFileEntry(String hostName)
        {
            String path = Environment.GetFolderPath(Environment.SpecialFolder.System);

            path = Path.Combine(path, @"drivers\etc\hosts");

            HostsFile file = new HostsFile(path);

            HostsFile.HostEntry entry = file.HostEntries.Find(e => e.HostName.Equals(hostName, StringComparison.OrdinalIgnoreCase));
            if (entry != null)
            {
                file.Elements.Remove(entry);
            }

            file.Save(path);
        }
Exemple #2
0
        private static void DoCommandLoop()
        {
            WriteCommands();

            while (true)
            {
                String line;
                switch (line = Console.ReadLine().ToUpperInvariant())
                {
                case "M":
                    ClearMsmgsEvent();
                    break;

                case "H":
                    HostsFile.AddHostsFileEntry("messenger.hotmail.com", "127.0.0.1");
                    break;

                case "R":
                    HostsFile.RemoveHostsFileEntry("messenger.hotmail.com");
                    break;

                case "Q":
                    StopServers();
                    return;

                case "Z":
                    return;

                case "C":
                    Console.Clear();
                    break;

                case "?":
                case "HELP":
                case "h":
                    WriteCommands();
                    break;

                default:
                    Console.WriteLine("Unrecognised Command: " + line);
                    break;
                }
            }
        }
Exemple #3
0
        public static void AddHostsFileEntry(String hostName, String ipAddress)
        {
            String path = Environment.GetFolderPath(Environment.SpecialFolder.System);

            path = Path.Combine(path, @"drivers\etc\hosts");

            HostsFile file = new HostsFile(path);

            HostsFile.HostEntry e = new HostsFile.HostEntry()
            {
                IPAddress = ipAddress,
                HostName  = hostName,
                Comment   = "Added by PinkEgoBox"
            };

            file.Elements.Add(e);

            file.Save(path);
        }