Last active
March 1, 2024 12:17
-
-
Save vimagick/e14ed4873e1b0b582f0e55e6fe6d5ed9 to your computer and use it in GitHub Desktop.
This file contains 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 | |
# | |
# shadowsocks connectivity check | |
# | |
INPUT_FILE=${1:?input file is empty} | |
OUTPUT_FILE=${2:?output file is empty} | |
LISTEN_ADDR=127.0.0.1 | |
LISTEN_PORT=1080 | |
PID_FILE=/tmp/ss-local.pid | |
WAIT_TIMEOUT=5 | |
TEST_URL=https://ipinfo.io | |
echo "host,port,method,password" > "$OUTPUT_FILE" | |
grep -oP '^ss://\S+@\S+:\d+' "$INPUT_FILE" | | |
while read uri; do | |
echo "### $uri ###" | |
if [[ $uri =~ ^ss://(.*)@(.*):([0-9]+)$ ]]; then | |
account=($(echo ${BASH_REMATCH[1]} | base64 -d 2>/dev/null | tr ':' ' ')) | |
if ((${#account[@]}!=2)); then | |
continue | |
fi | |
method=${account[0]} | |
password=${account[1]} | |
host=${BASH_REMATCH[2]} | |
port=${BASH_REMATCH[3]} | |
if lsof -nP -iTCP:$LISTEN_PORT -s TCP:listen; then | |
echo "Failed to listen on $LISTEN_ADDR:$LISTEN_PORT" | |
exit 1 | |
fi | |
echo ">>> ss-local -f $PID_FILE -s $host -p $port -b $LISTEN_ADDR -l $LISTEN_PORT -m $method -k $password" | |
if ss-local -f $PID_FILE -s $host -p $port -b $LISTEN_ADDR -l $LISTEN_PORT -m $method -k $password >/dev/null 2>&1; then | |
sleep $WAIT_TIMEOUT | |
echo ">>> curl -s -f -m $WAIT_TIMEOUT -w '\n' -x socks5h://$LISTEN_ADDR:$LISTEN_PORT $TEST_URL" | |
if curl -s -m $WAIT_TIMEOUT -w '\n' -x socks5h://$LISTEN_ADDR:$LISTEN_PORT $TEST_URL; then | |
echo "$host,$port,$method,$password" >> "$OUTPUT_FILE" | |
fi | |
kill $(cat $PID_FILE) | |
fi | |
fi | |
done | |
# csvlook "$OUTPUT_FILE" |
Author
vimagick
commented
Feb 29, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment