blob: 64faae03e014b90e3131b072fe29ec4401e71b15 [file] [log] [blame] [raw]
#!/bin/sh
# Copyright 2015-2022 Rivoreo
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
BLACKLIST_FILE="$HOME/.blacklist"
set -e
#[ -d "$HOME/.ssh" ] || mkdir "$HOME/.ssh"
#KNOWN_HOSTS_FILE="$HOME/.ssh/known_hosts"
#grep -Eq '^\[?116\.113\.133\.9(\]|[[:space:]])' "$KNOWN_HOSTS_FILE" || cat >> "$KNOWN_HOSTS_FILE" << EOF
known_hosts_file="`mktemp`"
trap 'rm -f "$known_hosts_file"' EXIT
cat > "$known_hosts_file" << EOF
[116.113.133.9]:6 ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBNDyYd6CBagb/jyYV5pvy42YOn4XMp0EuaIB8polNPgf9nXy/8b0fhGOjjmtDtY6swwoY9UsMdMzGgFNV3bZPRo=
[116.113.133.9]:6 ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCgIOe2WcJ4VJALGocMB0HWPNHJEFHpsAhx7PcsKcSovzxJh8gayPEWGI5l1sWqeR/71lR1CoUIywRIUWiDt4crBWi+jDdsWCewytO59Dmx+Ei4YduZOlMy78ffvEM8fYP1d2BJJ0874wpA9DuyBgaZkRZRmfivHQIUFyPq2fG8bWx9OpqtIC5//6o/fI785+sQedJRLacwrINdZM2J3kOQ6BVsWIP2J5pC4JAmUTNUvOcOipivPSqLyUwqsFOWnAeCxF9elFPyFD492RbxIhNOrIuWUjtM5Scnl+Yj/+Yk7uxOpWuUlxBr0qLen7jOiXpR5JMMSrpboG/TaJPIXLXN
EOF
ssh -o BatchMode=yes -o PubkeyAuthentication=no -o StrictHostKeyChecking=yes -o "GlobalKnownHostsFile $known_hosts_file" 116.113.133.9 -p 6 -l get-blacklist -T < /dev/null | while read -r a
do grep --line-regexp -Fq -- "$a" "$BLACKLIST_FILE" || printf %s\\n "$a" >> "$BLACKLIST_FILE"
done