Skip to content

Commit e9d1aaa

Browse files
cursoragentadysec
andcommitted
feat: Filter malicious IPs from trackers
Add blacklisting functionality to remove known bad IPs from tracker lists. Co-authored-by: admin <[email protected]>
1 parent 46857d0 commit e9d1aaa

File tree

4 files changed

+19
-1070
lines changed

4 files changed

+19
-1070
lines changed

blackstr.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
107.189.2.131

format.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,17 @@ fi
1919
# - 使用grep -oP 来匹配以http://, https://, udp://, wss://开头并且以/announce结尾的内容
2020
# - 不进行贪婪匹配
2121
# - 使用sed来省略默认端口
22+
# - 过滤掉包含blackstr.txt中恶意IP的URL
2223
tr ',' '\n' < "$input_file" | \
2324
grep -oP '(http|https|udp|wss)://[^/]+/announce' | \
2425
sed -E 's#(http://[^/]+):80/announce#\1/announce#; s#(https://[^/]+):443/announce#\1/announce#' | \
25-
sed 's/[ \t]*$//' > "$output_file"
26+
sed 's/[ \t]*$//' | \
27+
{
28+
if [ -f "blackstr.txt" ]; then
29+
grep -v -F -f blackstr.txt
30+
else
31+
cat
32+
fi
33+
} > "$output_file"
2634

2735
echo "Formatted trackers have been saved to $output_file"

test_trackers.sh

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,14 @@ fi
1818
# 清空输出文件
1919
> "$output_file"
2020

21-
# 读取文件并逐行处理
22-
while IFS= read -r tracker; do
21+
# 过滤掉包含blackstr.txt中恶意IP的URL,然后逐行处理
22+
{
23+
if [ -f "blackstr.txt" ]; then
24+
grep -v -F -f blackstr.txt "$input_file"
25+
else
26+
cat "$input_file"
27+
fi
28+
} | while IFS= read -r tracker; do
2329
protocol=$(echo "$tracker" | grep -oE '^[a-z]+')
2430

2531
case $protocol in
@@ -62,6 +68,6 @@ while IFS= read -r tracker; do
6268
echo "Unknown protocol: $protocol"
6369
;;
6470
esac
65-
done < "$input_file"
71+
done
6672

6773
echo "Testing complete."

0 commit comments

Comments
 (0)