Created
March 6, 2025 20:01
-
-
Save ioxorg/49af6eb61ac8fa477dc79dfd1a46969c to your computer and use it in GitHub Desktop.
Block BitTorrent via iptabls.
This file contains hidden or 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
#!/usr/bin/env bash | |
echo "Applying Torrent blocking rules..." | |
# Block Torrent algo string using Boyer-Moore (bm) | |
BLOCK_STRINGS_BM=( | |
"BitTorrent" | |
"BitTorrent protocol" | |
"peer_id=" | |
".torrent" | |
"announce.php?passkey=" | |
"torrent" | |
"announce" | |
"info_hash" | |
"/default.ida?" | |
".exe?/c+dir" | |
".exe?/c_tftp" | |
) | |
# Block Torrent keys using Knuth-Morris-Pratt (kmp) | |
BLOCK_STRINGS_KMP=( | |
"peer_id" | |
"BitTorrent" | |
"BitTorrent protocol" | |
"bittorrent-announce" | |
"announce.php?passkey=" | |
"find_node" | |
"info_hash" | |
"get_peers" | |
"announce" | |
"announce_peers" | |
) | |
# Apply rules for Boyer-Moore algorithm | |
for STRING in "${BLOCK_STRINGS_BM[@]}"; do | |
echo "Blocking (BM): $STRING" | |
iptables -A FORWARD -m string --algo bm --string "$STRING" -j DROP | |
done | |
# Apply rules for Knuth-Morris-Pratt algorithm | |
for STRING in "${BLOCK_STRINGS_KMP[@]}"; do | |
echo "Blocking (KMP): $STRING" | |
iptables -A FORWARD -m string --algo kmp --string "$STRING" -j DROP | |
done | |
echo "All BitTorrent blocking rules applied successfully!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
run it via the following command :
sudo bash -c "$(curl -sL https://gist.githubusercontent.com/alirezahabibzadeh/49af6eb61ac8fa477dc79dfd1a46969c/raw/2d31bd14c4fb23922fb1efcb3645b1f1c9e04614/block_bittorrent.sh)"