-
Notifications
You must be signed in to change notification settings - Fork 0
/
nukeHosts.bash
executable file
·64 lines (53 loc) · 2.09 KB
/
nukeHosts.bash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env bash
: <<'!COMMENT'
GGCOM - Bash - Utils - Nuke Hosts v201504162001
Louis T. Getterman IV (@LTGIV)
www.GotGetLLC.com | www.opensour.cc/ggcom/nukehosts
Example usage:
nukehosts.bash HOST [KNOWN_HOSTS_FILE]
!COMMENT
################################################################################
SOURCE="${BASH_SOURCE[0]}" # Dave Dopson, Thank You! - http://stackoverflow.com/questions/59895/can-a-bash-script-tell-what-directory-its-stored-in
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
SCRIPTPATH="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$SCRIPTPATH/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
################################################################################
SCRIPTPATH="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SCRIPTNAME=`basename "$SOURCE"`
LIBPATH="$( cd "$(dirname "${SCRIPTPATH}/../../")" ; pwd -P )/ggcom-bash-library"
################################################################################
source "${LIBPATH}/varsBash.bash"
source "${LIBPATH}/string.bash"
source "${LIBPATH}/version.bash"
################################################################################
source "${LIBPATH}/ip.bash"
################################################################################
#----- NOTICE: INFO
echo "`getVersion $0 header`"
echo;
#-----/NOTICE: INFO
#----- HOSTS FILE TARGET
if [ -z "$2" ]; then
TARGET=$HOME/.ssh/known_hosts
else
TARGET=${2}
fi
#-----/HOSTS FILE TARGET
#----- HOST
if [ -z "$1" ]; then
echo "Usage: ${SCRIPTNAME} host [known_hosts_file]"
exit;
fi
#----- HOST
echo "Known host file : ${TARGET}"
HOST=${1}
HOSTIP=`host ${1} | awk '{print $4}'`
# TO FIX: HOSTIP doesn't follow-through on aliases, and thus provides an invalid IP return
echo "Nuking Host Name : ${HOST}"
ssh-keygen -f ${TARGET} -R ${HOST} > /dev/null 2>&1
if valid_ipv4 $HOSTIP == true; then
echo "Nuking Host IP : ${HOSTIP}"
ssh-keygen -f ${TARGET} -R ${HOSTIP} > /dev/null 2>&1
fi