| Name | hosts-manager JSON |
| Version |
0.2.7
JSON |
| download |
| home_page | None |
| Summary | A script to manage the /etc/hosts file. |
| upload_time | 2024-08-03 23:42:09 |
| maintainer | None |
| docs_url | None |
| author | None |
| requires_python | >=3.6 |
| license | MIT |
| keywords |
|
| VCS |
 |
| bugtrack_url |
|
| requirements |
No requirements were recorded.
|
| Travis-CI |
No Travis.
|
| coveralls test coverage |
No coveralls.
|
# Hosts File Manager
This script manages the `/etc/hosts` file, allowing you to add, delete, list, update, backup, and restore entries.
> Inspired by the repository [hosts](https://github.com/rufflabs/hosts) by [rufflabs](https://github.com/rufflabs).
> **Warning**: Use this script with caution as it can modify system files, potentially disrupting network connections.
> Do not rely solely on the backup feature of this script to restore the hosts file in emergencies. Always maintain an independent backup of the original file.
> This script is designed to edit a specific section of the hosts file, but its behavior is not guaranteed.
## Demo Environment
To try out the script in an isolated environment without making changes to your system, you can use Docker. The following command sets up a demo environment where you can experiment with the script:
```sh
docker run -it --rm --hostname hosts-manager python:3.12-slim bash -c "apt-get update && apt-get install -y iputils-ping && pip install pipx && pipx install hosts-manager && pipx ensurepath && export PATH=\$PATH:/root/.local/bin && bash"
```
This command:
- Creates a temporary container with Python 3.12-slim.
- Installs `iputils-ping` to enable the ping feature.
- Installs `pipx` and the `hosts-manager` package.
- Adds the local bin directory to the PATH and opens a bash shell for you to interact with the script.



## Installation
Ensure Python >=3.12 is installed on your system. You can install the script using `pip`, `pipx`, or directly from the source code.
### Installing via GitHub
```sh
git clone https://github.com/Friedjof/hosts.git
cd hosts
pip install -r requirements.txt
```
### Installing via pip
You can install the package directly from PyPI:
```sh
pip install hosts-manager
```
### Installing via pipx
Alternatively, you can install the package using `pipx` for isolation:
```sh
pipx install hosts-manager
```
### Installation Using Makefile
The provided `Makefile` simplifies the build, installation, and testing process. Below are the steps to use the `Makefile`:
1. **Build the Package**:
This command will create source and wheel distributions of the package.
```sh
make build
```
2. **Install the Package Using pipx**:
This command installs the package in an isolated environment using `pipx`.
```sh
make install
```
3. **Install the Package in a Virtual Environment**:
Alternatively, you can install the package in a virtual environment.
```sh
make install-venv
```
4. **Uninstall the Package Using pipx**:
This command uninstalls the package from the `pipx` environment.
```sh
make uninstall
```
5. **Uninstall the Package from the Virtual Environment**:
This command uninstalls the package from the virtual environment.
```sh
make uninstall-venv
```
6. **Clean the Build Artifacts**:
This command removes the build artifacts and temporary files.
```sh
make clean
```
7. **Run Tests Using tox**:
This command runs the tests defined in the `tox` configuration.
```sh
make test
```
8. **Upload the Package to PyPI**:
This command uploads the built distributions to PyPI using `twine`.
```sh
make upload
```
9. **Run the Script Directly**:
This command runs the main script directly.
```sh
make run
```
## Usage
The script supports various commands to facilitate the management of the hosts file. Each command has its own parameters and options.
### Commands
- **add**: Adds an IP address and one or more hostnames to the hosts file.
- **del**: Deletes an IP address or hostname from the hosts file.
- **clear**: Clears all entries from the hosts file.
- **list**: Lists all entries from the hosts file.
- **update**: Updates an existing entry in the hosts file.
- **backup**: Backs up the hosts file and offers options to restore or remove backups.
### Options
- **--file**: The path to the hosts file (default: `hosts`).
### Examples
#### Add an IP address and hostname to the hosts file
```sh
hosts add 10.10.10.5 raspi-1.local
hosts add 10.10.10.4 raspi-2.local raspi-3.local raspi-4.local
```
#### Update an entry in the hosts file
```sh
hosts update raspi-1.local --ip 10.10.10.1
hosts update 10.10.10.1 --hostname raspi-10.local
hosts update 10.10.10.* --ip 10.10.10.10
hosts update raspi-.*.local --hostname raspi-10.local --ip 10.10.10.10
```
#### Delete an IP address or hostname from the hosts file
```sh
hosts del 10.10.10.5
hosts del raspi-1.local
hosts del 10.10.10.*
hosts del raspi-.*.local
```
#### Clear all entries from the hosts file
```sh
hosts clear
```
#### List all entries from the hosts file
```sh
hosts list
hosts list --section
hosts list --section --sort-by hostname
hosts list 10.10.10.* -s -b hostname
hosts list --ping
```
#### Backup the hosts file
```sh
hosts backup
hosts backup --file /etc/hosts --dir ~/.local/share/hosts
hosts backup --list 5
hosts backup --restore
hosts backup -r hosts-1631533200.bak
hosts backup --remove last
hosts backup -x oldest
hosts backup -x hosts-1631533200.bak
hosts backup --remove all
```
## Parameters
### General Parameters
- **--file**: The path to the hosts file (default: `/etc/hosts`).
### `add` Command
- **ip**: The IP address to add.
- **hosts**: The hostnames to add (separate multiple hostnames with spaces).
### `del` Command
- **identifier**: The IP address or hostname to delete. Supports regex patterns (e.g., `192.168.*` or `raspi-.*.com`).
### `clear` Command
- No additional parameters.
### `list` Command
- **--section**, `-s`: Only list entries from the managed section.
- **--sort-by**, `-b`: Sort the entries by IP address or hostname (default: `ip`).
- **--ping**, `-p`: Display the status of the IP addresses.
- **identifier**: The IP address or hostname to list (optional).
### `update` Command
- **identifier**: The IP address or hostname to update.
- **--ip**: The new IP address.
- **--hostname**: The new hostname.
### `backup` Command
- **--dir**: The directory to store the backups (default: `HostsFile.BACKUP_DIR`).
- **--file**: The path to the hosts file (default: `HostsFile.HOST_FILE`).
Mutually exclusive options:
- **--list**, `-l`: List backups.
- **--restore**, `-r`: Restore a backup file (optional: specific file).
- **--remove**, `-x`: Remove a backup file (optional: specific file or `oldest`, `last`, `all`).
## Contributing
If you find any issues or have feature requests, feel free to open an [issue](https://github.com/Friedjof/hosts/issues). Pull requests are also welcome!
## More Information
For detailed information on using each command and available parameters, run the script with the `--help` parameter:
```sh
hosts --help
```
Raw data
{
"_id": null,
"home_page": null,
"name": "hosts-manager",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": null,
"keywords": null,
"author": null,
"author_email": "Friedjof Noweck <git@noweck.info>",
"download_url": "https://files.pythonhosted.org/packages/64/6f/a4c070ece08bee0b3cc0331d33c094914f859feb0a69b4677d8f8bced0cd/hosts_manager-0.2.7.tar.gz",
"platform": null,
"description": "# Hosts File Manager\n\nThis script manages the `/etc/hosts` file, allowing you to add, delete, list, update, backup, and restore entries.\n\n> Inspired by the repository [hosts](https://github.com/rufflabs/hosts) by [rufflabs](https://github.com/rufflabs).\n\n> **Warning**: Use this script with caution as it can modify system files, potentially disrupting network connections.\n> Do not rely solely on the backup feature of this script to restore the hosts file in emergencies. Always maintain an independent backup of the original file.\n> This script is designed to edit a specific section of the hosts file, but its behavior is not guaranteed.\n\n## Demo Environment\n\nTo try out the script in an isolated environment without making changes to your system, you can use Docker. The following command sets up a demo environment where you can experiment with the script:\n\n```sh\ndocker run -it --rm --hostname hosts-manager python:3.12-slim bash -c \"apt-get update && apt-get install -y iputils-ping && pip install pipx && pipx install hosts-manager && pipx ensurepath && export PATH=\\$PATH:/root/.local/bin && bash\"\n```\n\nThis command:\n- Creates a temporary container with Python 3.12-slim.\n- Installs `iputils-ping` to enable the ping feature.\n- Installs `pipx` and the `hosts-manager` package.\n- Adds the local bin directory to the PATH and opens a bash shell for you to interact with the script.\n\n\n\n\n\n## Installation\n\nEnsure Python >=3.12 is installed on your system. You can install the script using `pip`, `pipx`, or directly from the source code.\n\n### Installing via GitHub\n\n```sh\ngit clone https://github.com/Friedjof/hosts.git\ncd hosts\npip install -r requirements.txt\n```\n\n### Installing via pip\n\nYou can install the package directly from PyPI:\n\n```sh\npip install hosts-manager\n```\n\n### Installing via pipx\n\nAlternatively, you can install the package using `pipx` for isolation:\n\n```sh\npipx install hosts-manager\n```\n\n### Installation Using Makefile\n\nThe provided `Makefile` simplifies the build, installation, and testing process. Below are the steps to use the `Makefile`:\n\n1. **Build the Package**:\n This command will create source and wheel distributions of the package.\n ```sh\n make build\n ```\n\n2. **Install the Package Using pipx**:\n This command installs the package in an isolated environment using `pipx`.\n ```sh\n make install\n ```\n\n3. **Install the Package in a Virtual Environment**:\n Alternatively, you can install the package in a virtual environment.\n ```sh\n make install-venv\n ```\n\n4. **Uninstall the Package Using pipx**:\n This command uninstalls the package from the `pipx` environment.\n ```sh\n make uninstall\n ```\n\n5. **Uninstall the Package from the Virtual Environment**:\n This command uninstalls the package from the virtual environment.\n ```sh\n make uninstall-venv\n ```\n\n6. **Clean the Build Artifacts**:\n This command removes the build artifacts and temporary files.\n ```sh\n make clean\n ```\n\n7. **Run Tests Using tox**:\n This command runs the tests defined in the `tox` configuration.\n ```sh\n make test\n ```\n\n8. **Upload the Package to PyPI**:\n This command uploads the built distributions to PyPI using `twine`.\n ```sh\n make upload\n ```\n\n9. **Run the Script Directly**:\n This command runs the main script directly.\n ```sh\n make run\n ```\n\n## Usage\n\nThe script supports various commands to facilitate the management of the hosts file. Each command has its own parameters and options.\n\n### Commands\n\n- **add**: Adds an IP address and one or more hostnames to the hosts file.\n- **del**: Deletes an IP address or hostname from the hosts file.\n- **clear**: Clears all entries from the hosts file.\n- **list**: Lists all entries from the hosts file.\n- **update**: Updates an existing entry in the hosts file.\n- **backup**: Backs up the hosts file and offers options to restore or remove backups.\n\n### Options\n\n- **--file**: The path to the hosts file (default: `hosts`).\n\n### Examples\n\n#### Add an IP address and hostname to the hosts file\n\n```sh\nhosts add 10.10.10.5 raspi-1.local\nhosts add 10.10.10.4 raspi-2.local raspi-3.local raspi-4.local\n```\n\n#### Update an entry in the hosts file\n\n```sh\nhosts update raspi-1.local --ip 10.10.10.1\nhosts update 10.10.10.1 --hostname raspi-10.local\nhosts update 10.10.10.* --ip 10.10.10.10\nhosts update raspi-.*.local --hostname raspi-10.local --ip 10.10.10.10\n```\n\n#### Delete an IP address or hostname from the hosts file\n\n```sh\nhosts del 10.10.10.5\nhosts del raspi-1.local\nhosts del 10.10.10.*\nhosts del raspi-.*.local\n```\n\n#### Clear all entries from the hosts file\n\n```sh\nhosts clear\n```\n\n#### List all entries from the hosts file\n\n```sh\nhosts list\nhosts list --section\nhosts list --section --sort-by hostname\nhosts list 10.10.10.* -s -b hostname\nhosts list --ping\n```\n\n#### Backup the hosts file\n\n```sh\nhosts backup\nhosts backup --file /etc/hosts --dir ~/.local/share/hosts\nhosts backup --list 5\nhosts backup --restore\nhosts backup -r hosts-1631533200.bak\nhosts backup --remove last\nhosts backup -x oldest\nhosts backup -x hosts-1631533200.bak\nhosts backup --remove all\n```\n\n## Parameters\n\n### General Parameters\n\n- **--file**: The path to the hosts file (default: `/etc/hosts`).\n\n### `add` Command\n\n- **ip**: The IP address to add.\n- **hosts**: The hostnames to add (separate multiple hostnames with spaces).\n\n### `del` Command\n\n- **identifier**: The IP address or hostname to delete. Supports regex patterns (e.g., `192.168.*` or `raspi-.*.com`).\n\n### `clear` Command\n\n- No additional parameters.\n\n### `list` Command\n\n- **--section**, `-s`: Only list entries from the managed section.\n- **--sort-by**, `-b`: Sort the entries by IP address or hostname (default: `ip`).\n- **--ping**, `-p`: Display the status of the IP addresses.\n- **identifier**: The IP address or hostname to list (optional).\n\n### `update` Command\n\n- **identifier**: The IP address or hostname to update.\n- **--ip**: The new IP address.\n- **--hostname**: The new hostname.\n\n### `backup` Command\n\n- **--dir**: The directory to store the backups (default: `HostsFile.BACKUP_DIR`).\n- **--file**: The path to the hosts file (default: `HostsFile.HOST_FILE`).\n\nMutually exclusive options:\n- **--list**, `-l`: List backups.\n- **--restore**, `-r`: Restore a backup file (optional: specific file).\n- **--remove**, `-x`: Remove a backup file (optional: specific file or `oldest`, `last`, `all`).\n\n## Contributing\n\nIf you find any issues or have feature requests, feel free to open an [issue](https://github.com/Friedjof/hosts/issues). Pull requests are also welcome!\n\n## More Information\n\nFor detailed information on using each command and available parameters, run the script with the `--help` parameter:\n\n```sh\nhosts --help\n```\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A script to manage the /etc/hosts file.",
"version": "0.2.7",
"project_urls": {
"Documentation": "https://github.com/Friedjof/hosts/blob/main/README.md",
"Homepage": "https://github.com/Friedjof/hosts",
"Source": "https://github.com/Friedjof/hosts",
"Tracker": "https://github.com/Friedjof/hosts/issues"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "efbd7d44afb96f79fb569a9d641b4525a73b98e30a32d4e8888af4be5a1febfc",
"md5": "caab581c991a49476c66adaad606cd0a",
"sha256": "adda519145d15c717e3ca62706a90449f32b4d2e260ce667e3e2d08a0ea7b1c9"
},
"downloads": -1,
"filename": "hosts_manager-0.2.7-py3-none-any.whl",
"has_sig": false,
"md5_digest": "caab581c991a49476c66adaad606cd0a",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 9719,
"upload_time": "2024-08-03T23:42:07",
"upload_time_iso_8601": "2024-08-03T23:42:07.735007Z",
"url": "https://files.pythonhosted.org/packages/ef/bd/7d44afb96f79fb569a9d641b4525a73b98e30a32d4e8888af4be5a1febfc/hosts_manager-0.2.7-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "646fa4c070ece08bee0b3cc0331d33c094914f859feb0a69b4677d8f8bced0cd",
"md5": "b80e0619dbc3b67ce239e4ae44bc570f",
"sha256": "7ffbe7339e513daec2300dd2c50c05dcc8d2cbf44f990e12a284310324f90935"
},
"downloads": -1,
"filename": "hosts_manager-0.2.7.tar.gz",
"has_sig": false,
"md5_digest": "b80e0619dbc3b67ce239e4ae44bc570f",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 11813,
"upload_time": "2024-08-03T23:42:09",
"upload_time_iso_8601": "2024-08-03T23:42:09.116896Z",
"url": "https://files.pythonhosted.org/packages/64/6f/a4c070ece08bee0b3cc0331d33c094914f859feb0a69b4677d8f8bced0cd/hosts_manager-0.2.7.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-08-03 23:42:09",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "Friedjof",
"github_project": "hosts",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [],
"lcname": "hosts-manager"
}