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
hosts
file, redirecting it to127.0.0.1
. - Remove URL: Remove a URL entry from the
hosts
file. - Show Hosts File Content: Display the current content of the
hosts
file. - Exit: Exit the script.
- Clone the repository or download the
manage_hosts.cmd
file. - Right-click on
manage_hosts.cmd
and 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.com
already exists in thehosts
file. - If it does not exist, the entry is added to the
hosts
file. - 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.com
exists in thehosts
file. - If it exists, the entry is removed from the
hosts
file. - Displays a confirmation message.
- Displays the current content of the
hosts
file. - 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
hosts
file. - The script uses
cmd /c
commands to handle elevated privileges for file operations.
This project is licensed under the MIT License.