Coder Social home page Coder Social logo

hosts's Introduction

hosts

Short script to automate editing your hosts file

Usage

I'm running the script locally on a Windows machine, running hosts.py from the location I've checked out the code with a batch script I've named hosts.bat:

@echo off
python C:\Users\[username]\Documents\GitHub\hosts\hosts.py %*

The rest of the documentation assumes you have the Python script aliased to a hosts command.

Lookup Hosts File Entry

Lookup the current IP address for a given host name, according to the hosts file:

~:$ hosts --get hostname
hostname 192.168.1.1

Lookup the current IP address for any number of given host names, according to the hosts file:

~:$ hosts --get hostname1 hostname2 hostname3
hostname1 192.168.1.13
hostname2 192.168.1.14
hostname3 192.168.1.15

Add a Hosts File Entry

Set a host to resolve to a particular IP address (will overwrite your current hosts file with new contents):

~:$ hosts --set 192.168.1.10 hostname

~:$ hosts --get hostname
hostname 192.168.1.10

Set any number of hosts to resolve to a particular IP address (will overwrite your current hosts file with new contents):

~:$ hosts --set 192.168.1.10 hostname1 hostname2 hostname3

~:$ hosts --get hostname1 hostname2 hostname3
hostname1 192.168.1.10
hostname2 192.168.1.10
hostname3 192.168.1.10

Add a Hosts File Entry Based On Existing Entry

Set a host to resolve to whatever IP address the hosts file resolves another host name to:

~:$ hosts --get hostname
hostname 192.168.1.10

~:$ hosts --alias hostname hostname1

~:$ hosts --get hostname hostname1
hostname 192.168.1.10
hostname1 192.168.1.10

Other Notes

Any modifications to the hosts made by the script will completely overwrite the file. . I recommend backing it up before making substantial changes.

Add the --dry option to any opertion that overwrites the hosts files to instead output the results to the screen without modifying the actual hosts file.

hosts's People

Contributors

mdomi avatar

Watchers

Vreddhi Bhat avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.