This repository contains a Windows batch file script for managing the hosts file located in the C:\Windows\System32\drivers\etc\ directory. The script allows you to add, remove, and view entries in the hosts file. The script requires administrative privileges to modify the hosts file.
- Add URL: Add a URL to the
hostsfile, redirecting it to127.0.0.1. - Remove URL: Remove a URL entry from the
hostsfile. - Show Hosts File Content: Display the current content of the
hostsfile. - Exit: Exit the script.
- Clone the repository or download the
manage_hosts.cmdfile. - Right-click on
manage_hosts.cmdand select "Run as administrator" to ensure the script has the necessary privileges.
Upon running the script, you will be presented with the following menu:
================================
Hosts File Management Script Please choose an option:
Add URL to hosts file Remove URL from hosts file Show hosts file content Exit Enter your choice (1/2/3/4):
- Prompts you to enter a URL to block (e.g.,
example.com). - Checks if the entry
127.0.0.1 example.comalready exists in thehostsfile. - If it does not exist, the entry is added to the
hostsfile. - Displays a confirmation message.
- Prompts you to enter a URL to unblock (e.g.,
example.com). - Checks if the entry
127.0.0.1 example.comexists in thehostsfile. - If it exists, the entry is removed from the
hostsfile. - Displays a confirmation message.
- Displays the current content of the
hostsfile. - Pauses to allow you to read the content before returning to the main menu.
- Exits the script.
- Ensure that you run the script with administrative privileges to allow it to modify the
hostsfile. - The script uses
cmd /ccommands to handle elevated privileges for file operations.
This project is licensed under the MIT License.