Skip to content
📍 Manage /etc/hosts in an organized way by Python
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
tests
.travis.yml
README.md
get_ssh_list_from_url.py
python-hosts-tool.py

README.md

Build Status PRs Welcome

LinkedIn Github slack

python-hosts-tool

Manage /etc/hosts in an organized way by Python

Read more: https://www.dennyzhang.com/audit_hostsfile

Principle:

  • Be safe: When remove, make sure it's an exact match; When add, make sure no conflicts
  • Can audit: backup old version, if we have changed it

Online Usage

##        # Examine hosts file, and detect unexpected changes
##        python ./python-hosts-tool.py --action examine --examine_hosts_file ./tests/test_hosts
##
##        # Add a list of new hosts entries
##        python ./python-hosts-tool.py --action add --add_hosts_file ./tests/test_hosts
##
##        # Remove a list of existing hosts
##        python ./python-hosts-tool.py --action remove --remove_hosts_file ./tests/test_hosts

How to Install

pip install python-hosts==0.3.7
# get the tool
wget -O python-hosts-tool.py \
    https://raw.githubusercontent.com/DennyZhang/python-hosts-tool/master/python-hosts-tool.py

# Or git clone
git clone git@github.com:DennyZhang/python-hosts-tool.git

How to Use

cat ./tests/test_hosts
45.33.87.75 www.dennytest.com
104.236.158.226 repo.dennytest.com
  • Run command

How To Run test

cd tests
sudo bash -ex ./test.sh

TODO Items

  • Send PR for safe delete to python-hosts

https://github.com/jonhadfield/python-hosts

https://pypi.python.org/pypi/python-hosts/0.3.7

Code is licensed under MIT License.

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.