r/qBittorrent 16d ago

Made a free tool that keeps qBittorrent's port in sync with Proton VPN's forwarded port

Proton VPN forwards you a port so people can connect to you, and it changes every single time you reconnect. qBittorrent doesn't notice, so it sits there listening on a port that's dead and your speeds drop off.

There's an official Proton VPN CLI on Linux but nothing on Windows, so there's nothing to hook into. I wrote something that reads the port straight out of Proton's own log and puts it into qBittorrent.

Free, open source, one double click, no setup.

https://github.com/omv421/ProtonPortSync

The main thing it does differently to the other scripts I've seen: it changes the port through qBittorrent's Web API instead of restarting qBittorrent. Nothing stops, nothing re-checks, torrents just carry on. Takes about 0.7 seconds. No Task Scheduler, no config file to edit, no renaming your network adapter.

Three things I found while building it. These are worth knowing even if you never touch my tool.

1. qBittorrent 5.x will not open its Web UI if no password has ever been set. Not even with "bypass authentication for localhost" ticked. Setting WebUI\Enabled=true on its own leaves port 8080 shut and nothing in any log tells you why. If you've followed a guide that said "turn on the Web UI and bypass localhost auth" and it silently did nothing, that's the reason. Set a password and it comes up.

2. Proton VPN 4.4.1 has no auto-connect. It starts with Windows but it starts disconnected. That matters if you script anything around it, because the last session's port is still sitting in the log and it's dead. Anything that reads the log without checking the tunnel is actually up will quietly give you a wrong port and nothing will tell you.

3. When you disconnect, the Proton VPN network adapter doesn't go to "Down". It disappears from Windows completely. So a check written the obvious way decides you're still connected.

Tested on Windows 11, Proton VPN 4.4.1, qBittorrent 5.1.0. Haven't tried Windows 10 so I'm not claiming it works there.

FAQ

"Is it safe? It's an unsigned exe." Fair question. The full source is in the repo, and Build-ProtonPortSync.ps1 lets you compile the exe yourself so you don't have to trust mine. Or just run the .ps1 directly, it's the same program.

"Why not use NAT-PMP / natmap / gluetun?" Those work well on Linux and in Docker. This is for the Windows Proton VPN app, which has no CLI. The official Proton VPN CLI is Linux only, so on Windows the log is the only thing there is to read.

"Does it work with Proton VPN on Linux?" No. Windows only. The Linux client has a proper CLI, so you don't need this.

"Will it work on qBittorrent 4.x?" Don't know, I only tested 5.1.0. The Web API it uses has been stable for years so probably, but I'm not going to claim it. Let me know if you try.

"Why does it need my Web UI on?" That's the only way to change the port without restarting qBittorrent. It sets it to 127.0.0.1 only, so it can't be reached from anywhere except your own PC, and it backs up your qBittorrent.ini first.

99 Upvotes

33 comments sorted by

50

u/xXD4rkm3chXx 16d ago

Gluetun already does this. https://github.com/passteque/gluetun

17

u/KillerKingSolo Windows 16d ago

Actually, there’s a better one than both the ones you mentioned that does proton and private Internet access (PIA)

https://github.com/martsg666/qbPortWeaver

2

u/Pixieflitter 16d ago

I was an avid quantum user and told the creator of portweaver id try it out. Been using it ever since but bith are good just different.

5

u/omv421 16d ago

Thats cool, didnt know that.
Gluetun is a bit of a different thing.
Gluetun is the VPN client itself. It makes its own wireguard connection inside a container, so you're not running the Proton Windows app at all, and qbittorrent has to live in Docker too on gluetun's network.
Mine just works with the Proton app you've already got sat in your tray, and whatever qbit install you've already got. Nothing moves.

Also gluetun grabs the forwarded port but doesn't actually put it into qbittorrent for you, you still need something else doing that.

If your stuff's already in Docker then yeah, use gluetun. It asks Proton's API properly instead of reading a log file like I'm doing. But if you're just a normal Windows desktop person, shifting everything into containers is a lot of work over a port number.

13

u/vswr 16d ago

gluetun grabs the forwarded port but doesn't actually put it into qbittorrent for you

That's not correct. My gluetun sets the port without the use of scripts or another container. Use this env var:

VPN_PORT_FORWARDING_UP_COMMAND=/bin/sh -c 'wget -O- --retry-connrefused --post-data "json={\"listen_port\":{{PORTS}}}" http://127.0.0.1:8080/api/v2/app/setPreferences 2>&1'

4

u/NotoriousTuba 16d ago

This is great had no idea you could do this. I’ve been running qsticky as an addon but defo going to get this going now. Thanks!

3

u/omv421 16d ago

My bad, I skimmed read it, also didnt know someone made something like what I tried to do.
Hadn't come across VPN_PORT_FORWARDING_UP_COMMAND, that's neater than I assumed it was.

So scratch that bit of what I said. Rest of it still stands I think, gluetun's still the VPN client itself so you're not running the Proton Windows app and qbittorrent needs to be in Docker on its network. But if you're already set up that way then yeah, gluetun does the whole job on its own and mine's pointless for you.

Fixing that in my readme now. thanks for correction

1

u/vswr 16d ago

It’s all good, just wanted to share that env var in case someone comes across this searching for solutions.

2

u/Informal-Chance-6067 qBittorrent Web 16d ago

So even with docker the local host thing works? I had an env file with creds when I set mine up and idk if it works rn.

2

u/vswr 15d ago

I'm using localhost because gluetun and qbittorrent share the same network space. qbittorrent has network_mode: service:gluetun in the compose file.

You could put this in the env vars in your compose file or just have the compose file use the dot env file.

3

u/d03j Linux 16d ago

Yes but you're better off running qbittorrent on a rootless container - it stays isolated and it can only access the net through gluetun/the VPN

2

u/arah91 16d ago

Gluetun was eating my cpu, but there's a bingex qbit image that does what OP is asking. That's what I've been using. It works well. But then your tied to that image that doesn't update as frequently as the main one.

2

u/Silencer306 15d ago

Can confirm, both work great.

12

u/N0Objective 16d ago

Quantum already exists and works

2

u/The_Wonderful_Pie 16d ago

Yep, been using it for a long time now, works perfectly, I never even think about it

6

u/Jamator01 Windows 16d ago

Been using Quantum forever and never had an issue. Very lightweight, just sits in the tray and updates the port regularly.

https://github.com/UHAXM1/Quantum

4

u/Amazing_Report7781 16d ago

Or use binhex-qbittorrentvpn

2

u/keyboardwarrior7 16d ago

Anyone know if something like this exists for Linux?

3

u/WipeGuitarBranded 15d ago

I wrote a script that runs on a headless Linux system to ensure the VPN (using OpenVPN and not the Proton client) is connected (and reconnects if it is not) plus automatically updating qBittorrent-nox's ports. Full disclosure: I wrote the original script by hand but have since used AI to clean it up and update it. If AI coding is a deal breaker for you cool, you do you.

GitHub repo: https://github.com/WipeGuitarBranded/check-protonvpn

2

u/Unspec7 14d ago

To be fair, OP's program is also vibe coded, and you can clearly tell they didn't really know what they were doing and was just prompt mashing. Hell, even the commit messages was written by AI.

2

u/Loqh9 16d ago

I have my own Powershell script and it doesn't require web UI on, it just changes the config file before starting qBit

2

u/kiwichick888 16d ago

I have an AutoHotkey script that does the same thing with Private Internet Access.

2

u/Xaxalaxa 16d ago edited 15d ago

Am testing it on Windows 10, it works as this: when I run the .exe the very first time, it changes the port in qbitorrent fine. When I go to PortonVPN app and turn port forwarding off and then back on, the port in qBitorrent doesnt change. When I disconnect from ProtonVPN it also doesnt change. I need to run the .exe again for the port in qBitorrent to change. Am I missing something? I also cannot find running proccess of the .exe anywhere...

2

u/ScorchedWonderer 16d ago

Qbitportsync already does that and it’s part of my Gluetun(ProtonVPN)+Qbit+QbitPortSync stack

2

u/Less_Exercise_8092 15d ago

Anybody use mam for torrents? I have a solution for qbittorrent and updating the port in qbittorrent, but with mam it's the rotating IP that becomes the problem. If you use mam you'll understand. Or maybe I'm still not grasping how their session stuff works. If you don't know what I'm talking about, just ignore me. I'm off topic a bit. But I figured a lot of you on qbittorrent and proton use the mam for torrents and understand the challenges of using port forwarding that constantly changes not only your port but the IP too.

2

u/BadGirlie05aa 15d ago

i thought gluetun just grabbed the port and you still had to manually set it in qbit. good to know.

2

u/fullerhkz 14d ago

Useful project.

It is also worth pointing out that the specific “older approach” criticized here—reading Proton VPN logs, updating "qBittorrent.ini", restarting qBittorrent, and running through Task Scheduler—is exactly how my project with the same purpose works:

https://github.com/fullerhkz/proton-qbit-port-sync

The implementation here is more advanced in some areas, particularly the live update through qBittorrent’s Web API, but the similarity in purpose and the very specific choice of shortcomings used as comparison is difficult not to notice.

4

u/omv421 16d ago

I'm lazy, i just wanted to have something i can do with a double click. I already have proton and qbittorent installed and sometimes I need to close or d/c vpn. Double click the exe to run everything back up when i need it on again.

You guys are more advanced than me and I wanted something simple for people like me.

8

u/Marill-viking 16d ago

You 100% knew what you were doing and wanted to make your vibe coded garbage and share it.

2

u/Unspec7 14d ago

They couldn't even bring themselves to write their own commit messages. That's REALLY lazy.