Skip to content

Instantly share code, notes, and snippets.

@realmovestar
Created November 18, 2019 02: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 realmovestar/b05b0c47cececb6c14512e4e47d082ee to your computer and use it in GitHub Desktop.
Save realmovestar/b05b0c47cececb6c14512e4e47d082ee to your computer and use it in GitHub Desktop.
#!/bin/bash
# stdin에서 IP PORT 형식으로 입력 받아서 해당 서버에 접속가능한지 확인해줌.
check() {
echo -n "$1:$2 "
# timeout -k 5 5
nc -z -w 5 $1 $2 &> /dev/null \
&& echo -e '\e[32msucccess\e[0m' \
|| echo -e '\e[31mfail\e[0m'
}
# IFS=$'\n'
while read entry; do
if [[ ${entry:=\#} = \#* ]]; then
echo $entry
continue
fi
temp=($entry)
IP="${temp[0]}"
PORT="${temp[1]}"
check $IP $PORT
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment