Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
feat: Filter malicious IPs from trackers
Add blacklisting functionality to remove known bad IPs from tracker lists.

Co-authored-by: admin <[email protected]>
  • Loading branch information
cursoragent and adysec committed Sep 17, 2025
commit e9d1aaa04073e577ce340978a37d2d69c4c1511d
1 change: 1 addition & 0 deletions blackstr.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
107.189.2.131
10 changes: 9 additions & 1 deletion format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,17 @@ fi
# - 使用grep -oP 来匹配以http://, https://, udp://, wss://开头并且以/announce结尾的内容
# - 不进行贪婪匹配
# - 使用sed来省略默认端口
# - 过滤掉包含blackstr.txt中恶意IP的URL
tr ',' '\n' < "$input_file" | \
grep -oP '(http|https|udp|wss)://[^/]+/announce' | \
sed -E 's#(http://[^/]+):80/announce#\1/announce#; s#(https://[^/]+):443/announce#\1/announce#' | \
sed 's/[ \t]*$//' > "$output_file"
sed 's/[ \t]*$//' | \
{
if [ -f "blackstr.txt" ]; then
grep -v -F -f blackstr.txt
else
cat
fi
} > "$output_file"

echo "Formatted trackers have been saved to $output_file"
12 changes: 9 additions & 3 deletions test_trackers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,14 @@ fi
# 清空输出文件
> "$output_file"

# 读取文件并逐行处理
while IFS= read -r tracker; do
# 过滤掉包含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
Expand Down Expand Up @@ -62,6 +68,6 @@ while IFS= read -r tracker; do
echo "Unknown protocol: $protocol"
;;
esac
done < "$input_file"
done

echo "Testing complete."
Loading