2008年(787)
分类:
2008-09-25 16:08:57
purge()
{
usage()
{
echo "*** cleanup the specified host key cache in .ssh/known_hosts ***"
echo "Usage: purge 16.18"
#return # cannot return in a built-in function
}
[ $# -lt 1 ] || [ $# -gt 2 ] || [ ! `echo $1 | sed -n '/\./p'` ] && usage && return
unset BADHOST && BADHOST="192.168.$1"
[ "${1%%.*}" == "15" ] || [ "${1%%.*}" == "88" ] && BADHOST="172.16.$1"
[ "${1%%.*}" == "10" ] || [ "${1%%.*}" == "8" ] && BADHOST="10.10.$1"
#四个特殊内网网段的例外:
# 10.10.10.0/24 10.10.8.0/24 172.16.15.0/24 172.16.88.0/24
[ "x$BADHOST" != "x192.168." ] && {
echo -n "Remove $BADHOST from $HOME/.ssh/known_hosts "
sed -e "/^$BADHOST\ /d" $HOME/.ssh/known_hosts > $HOME/.ssh/known_hosts.purged
install -m 600 $HOME/.ssh/known_hosts.purged $HOME/.ssh/known_hosts
echo successfully!
}
}