-
Notifications
You must be signed in to change notification settings - Fork 186
Expand file tree
/
Copy pathtest_trackers.sh
More file actions
executable file
·95 lines (87 loc) · 2.77 KB
/
test_trackers.sh
File metadata and controls
executable file
·95 lines (87 loc) · 2.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/bin/bash
# 检查是否提供了文件名作为参数
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <file>"
exit 1
fi
input_file="$1"
output_file_main="trackers_best.txt"
output_file_http="trackers_best_http.txt"
output_file_https="trackers_best_https.txt"
output_file_udp="trackers_best_udp.txt"
output_file_wss="trackers_best_wss.txt"
# 检查文件是否存在
if [ ! -f "$input_file" ]; then
echo "Error: File not found."
exit 1
fi
# 清空所有输出文件
> "$output_file_main"
> "$output_file_http"
> "$output_file_https"
> "$output_file_udp"
> "$output_file_wss"
# 过滤掉包含blackstr.txt中恶意IP的URL,然后逐行处理
{
if [ -f "blackstr.txt" ]; then
grep -v -F -f blackstr.txt "$input_file"
else
cat "$input_file"
fi
} | while IFS= read -r tracker; do
protocol=$(echo "$tracker" | grep -oE '^[a-z]+')
case $protocol in
http)
if curl -s -f -m 1 "$tracker" &>/dev/null; then
echo "Success: $tracker"
echo "$tracker" >> "$output_file_main"
echo "$tracker" >> "$output_file_http"
else
echo "Failed: $tracker"
fi
;;
https)
if curl -s -f -m 1 "$tracker" &>/dev/null; then
echo "Success: $tracker"
echo "$tracker" >> "$output_file_main"
echo "$tracker" >> "$output_file_https"
else
echo "Failed: $tracker"
fi
;;
udp)
host=$(echo "$tracker" | cut -d'/' -f3)
port=$(echo "$host" | cut -d':' -f2)
host=$(echo "$host" | cut -d':' -f1)
if nc -zuv -w 1 "$host" "$port" &>/dev/null; then
echo "Success: $tracker"
echo "$tracker" >> "$output_file_main"
echo "$tracker" >> "$output_file_udp"
else
echo "Failed: $tracker"
fi
;;
wss)
# WSS tracker 测试 - 使用简单的 TCP 连接测试
host=$(echo "$tracker" | sed 's|wss://||' | cut -d'/' -f1)
port=$(echo "$host" | cut -d':' -f2)
if [ "$port" = "$host" ]; then
port=443 # WSS 默认端口
host=$(echo "$host" | cut -d':' -f1)
else
host=$(echo "$host" | cut -d':' -f1)
fi
if nc -zv -w 1 "$host" "$port" &>/dev/null; then
echo "Success: $tracker"
echo "$tracker" >> "$output_file_main"
echo "$tracker" >> "$output_file_wss"
else
echo "Failed: $tracker"
fi
;;
*)
echo "Unknown protocol: $protocol"
;;
esac
done
echo "Testing complete."