Last active
December 19, 2024 15:07
-
-
Save iykex/37d741064c77f473c7b8d054bf53b45c to your computer and use it in GitHub Desktop.
stop_transmission.sh
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
#!/bin/bash | |
#author: @deviyke | |
stop_systemd_service() { | |
if systemctl is-active --quiet transmission-daemon > /dev/null 2>&1; then | |
systemctl stop transmission-daemon > /dev/null 2>&1 | |
fi | |
} | |
stop_initd_service() { | |
if service transmission-daemon status > /dev/null 2>&1; then | |
service transmission-daemon stop > /dev/null 2>&1 | |
fi | |
} | |
block_torrent_traffic() { | |
if command -v ufw > /dev/null 2>&1; then | |
echo "Blocking torrent traffic using ufw..." | |
sudo ufw deny out 6881:6889/tcp > /dev/null 2>&1 | |
sudo ufw deny out 6881:6889/udp > /dev/null 2>&1 | |
sudo ufw reload > /dev/null 2>&1 | |
echo "Torrent traffic blocked using ufw." | |
elif command -v iptables > /dev/null 2>&1; then | |
echo "Blocking torrent traffic using iptables..." | |
sudo iptables -A OUTPUT -p tcp --dport 6881:6889 -j REJECT > /dev/null 2>&1 | |
sudo iptables -A OUTPUT -p udp --dport 6881:6889 -j REJECT > /dev/null 2>&1 | |
sudo iptables -A OUTPUT -m string --string "BitTorrent" --algo bm -j REJECT > /dev/null 2>&1 | |
sudo iptables -A OUTPUT -m string --string "BitTorrent protocol" --algo bm -j REJECT > /dev/null 2>&1 | |
sudo iptables -A OUTPUT -m string --string "peer_id=" --algo bm -j REJECT > /dev/null 2>&1 | |
sudo iptables -A OUTPUT -m string --string ".torrent" --algo bm -j REJECT > /dev/null 2>&1 | |
echo "Torrent traffic blocked using iptables." | |
else | |
echo "No supported firewall (ufw or iptables) is installed. Exiting." | |
exit 1 | |
fi | |
} | |
# Stop the transmission-daemon service | |
if pidof systemd > /dev/null 2>&1; then | |
stop_systemd_service | |
elif pidof init > /dev/null 2>&1; then | |
stop_initd_service | |
fi | |
# Block torrent traffic | |
block_torrent_traffic |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment