Files
42_10/test_connection.sh
2026-04-08 18:19:24 +08:00

35 lines
977 B
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# --- 這裡要改成你真正有開的 Port ---
TARGET_IP="125.229.110.50"
# PORTS=("51433")
PORTS=("51433" "31433")
echo "--- [第一步:身份確認] ---"
MY_INFO=$(curl -s https://ip.lotimmy.com/json)
MY_IP=$(echo $MY_INFO | jq -r '.ip')
MY_REGION=$(echo $MY_INFO | jq -r '.region_name')
MY_ASN=$(echo $MY_INFO | jq -r '.asn_org')
echo "目前位置:$MY_REGION ($MY_ASN)"
echo "對外 IP $MY_IP"
# 判斷是否為台灣 IP
SHOULD_PASS=false
if [[ "$MY_REGION" == *"Taipei"* ]] || [[ "$MY_ASN" == *"Data Communication"* ]]; then
SHOULD_PASS=true
fi
echo -e "\n--- [第二步:連線測試] ---"
for PORT in "${PORTS[@]}"
do
# 測試連線
nc -zv -w 5 $TARGET_IP $PORT > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo "[成功] Port $PORT 連線正常。"
else
echo -n "[攔截] Port $PORT 無法連線。"
[ "$SHOULD_PASS" = true ] && echo " (錯誤:你是台灣 IP 卻被擋掉!)" || echo ""
fi
done