Skip to content

Instantly share code, notes, and snippets.

@atpons
Last active November 11, 2019 08:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atpons/b9c1f1b806ee7b52012d74fd600ade12 to your computer and use it in GitHub Desktop.
Save atpons/b9c1f1b806ee7b52012d74fd600ade12 to your computer and use it in GitHub Desktop.
thelper
#!/bin/bash
############################################################
# thelper
# ----------------------------------------------------------
# Keep exist route specified host.
# ----------------------------------------------------------
# + Usage
# $ thelper google.com (Add/Delete)
# + Install
# $ sudo bash -c 'curl <gist_url> > /usr/local/bin/thelper'
# License: MIT (@atpons)
############################################################
host="$1"
ip=`dig +short $host`
echo "[*] Got $host is $ip"
gw=$(ip route | awk '/default/ { print $3 }')
echo "[*] Default gateway: $gw"
add=$(sudo ip route add $ip/32 via $gw)
if [ $? -ne 0 ]; then
sudo ip route del $ip/32 via $gw
echo "[-] Delete route."
exit 0
else
echo "[-] Add route."
fi
@atpons
Copy link
Author

atpons commented Nov 11, 2019

Install
sudo bash -c "curl https://gist.githubusercontent.com/atpons/b9c1f1b806ee7b52012d74fd600ade12/raw/051300c63b5bf9b38721923034ff671ecc63fb85/thelper > /usr/local/bin/thelper" && sudo chmod +x /usr/local/bin/thelper

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment