Created
October 26, 2023 04:56
-
-
Save ChenYFan/8b5ba92875a195a992c7d451490971e4 to your computer and use it in GitHub Desktop.
qBittorrent && natmap
This file contains 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/sh | |
# Natter/NATMap | |
private_port=$4 # Natter: $3; NATMap: $4 | |
public_port=$2 # Natter: $5; NATMap: $2 | |
echo $1 $2 $3 $4 | |
# qBittorrent. | |
qb_web_port="" | |
qb_username="" | |
qb_password="" | |
echo "Update qBittorrent listen port to $public_port..." | |
# Update qBittorrent listen port. | |
qb_cookie=$(curl -s -i --header "Referer: http://localhost:$qb_web_port" --data "username=$qb_username&password=$qb_password" http://localhost:$qb_web_port/api/v2/auth/login | grep -i set-cookie | cut -c13-48) | |
curl -X POST -b "$qb_cookie" -d 'json={"listen_port":"'$public_port'"}' "http://localhost:$qb_web_port/api/v2/app/setPreferences" | |
echo "Update iptables..." | |
# Use iptables to forward traffic. | |
LINE_NUMBER=$(iptables -t nat -nvL --line-number | grep ${private_port} | head -n 1 | grep -o '^[0-9]+') | |
iptables -t nat -D PREROUTING $LINE_NUMBER | |
iptables -t nat -I PREROUTING -p tcp --dport $private_port -j REDIRECT --to-port $public_port | |
echo "Done." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment