Last active
November 25, 2022 22:17
-
-
Save neuthral/0ff41380958321d69888fead29d510ee to your computer and use it in GitHub Desktop.
Loop through list of trackers and test if they are alive using nc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
## | |
# Loop through list of trackers and test if they are alive using nc | |
# nc -v -z -w 3 -u "$host" "$port" | |
## | |
usage () { | |
printf '\n%s\n' "Loop through list of trackers and test if they are alive using nc" | |
printf '\n%s\n\n' "Usage: $(basename "$0") [list-of-trackers.file]" | |
exit | |
} | |
if [[ ! -f $1 ]]; then | |
usage | |
fi | |
while read -r line; do | |
FIELDS=($(echo $line | grep -o "[a-z0-9.-]*" | tr '\n' ' ')) | |
if [[ ${FIELDS[0]} == "udp" ]]; then | |
# set udp flag if protocol is udp | |
args="-z -v -w 1 -u" | |
else | |
args="-z -v -w 1" | |
fi | |
if [[ ! ${FIELDS[1]} ]]; then | |
echo '-' | |
else | |
if nc $( echo "$args ${FIELDS[1]} ${FIELDS[2]}"); then | |
echo "$line" >> alive.txt | |
fi | |
fi | |
done <"$1" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment