HostCLI
To ease the work for adding host into localhost. I'm preparing the script in python
#!/usr/bin/env python3
import subprocess
def add_hosts_entry():
ip_address = input("Enter the IP address: ")
domains = input("Enter the domain names (separated by spaces): ")
entry = f"{ip_address} {domains}"
try:
command = ["sudo", "tee", "-a", "/etc/hosts"]
process = subprocess.Popen(command, stdin=subprocess.PIPE, text=True)
process.communicate(entry + "\n")
print("Entry added successfully!")
except Exception as e:
print(f"Error: {e}")
if __name__ == "__main__":
add_hosts_entry()
Save this as hostcli.py
Put into ~/.bashrc
or ~/.zshrc
based on your preference.
alias hostcli='python3 /path/to/hostcli.py '
Last updated