VPN interface sometimes changes after rebooting qBittorrent. 'The configured network interface is invalid. Interface: "iftype53_32768"' #17076

Open
opened 2026-02-22 03:39:27 -05:00 by deekerman · 2 comments
Owner

Originally created by @lw4242 on GitHub (Aug 14, 2025).

qBittorrent & operating system versions

qBittorrent: v5.1.2
Operating system: Windows 11 Pro 24H2 26100.4652
ProtonVPN client version: 4.2.1

What is the problem?

I am finding sometimes when rebooting qBittorrent there are no connections even with the correct port bound. In these cases when I go to look at the network interface options, "ProtonVPN" appears twice in the drop down, and selecting the 'other' ProtonVPN restores normalcy (and the 'original' ProtonVPN entry disappears). This seems to be a well documented issue that is easily fixed in the GUI, but I run a script that reboots qBittorrent daily so I am running into it a lot. In the most recent incidence of this problem, the following appears in qBittorrent.log:

(C) 2025-08-13T05:00:30 - The configured network interface is invalid. Interface: "iftype53_32768"

I then selected the 'other' ProtonVPN from the dropdown and looked at qbittorrent.ini. The interface now shows up as

Session\Interface=iftype53_32769

I'm not entirely sure how to interpret this. I've confirmed the ProtonVPN client has not updated from before to after this error occurs, however it is configured to connect to a random server on each startup.

As a workaround, does anyone know how I can determine from qBittorrent's settings files which of these iftype53 values is correct (i.e. is there a way I can programmatically identify what the Session\Interface value should be for the 'other' ProtonVPN entry, seeing as both appear as Session\InterfaceName=ProtonVPN)? Worth noting I did also have this problem with NordVPN occasionally so I don't think it is Proton that is the issue (or if it is then NordVPN is affected by the same problem)

Thanks in advance!

Steps to reproduce

This issue happens after qBittorrent is rebooted. I also restart my VPN simultaneously via script and the problem only occurs intermittently so I am not sure how to reproduce

Additional context

No response

Log(s) & preferences file(s)

qBittorrent.txt

qbittorrent.log

Originally created by @lw4242 on GitHub (Aug 14, 2025). ### qBittorrent & operating system versions qBittorrent: v5.1.2 Operating system: Windows 11 Pro 24H2 26100.4652 ProtonVPN client version: 4.2.1 ### What is the problem? I am finding sometimes when rebooting qBittorrent there are no connections even with the correct port bound. In these cases when I go to look at the network interface options, "ProtonVPN" appears twice in the drop down, and selecting the 'other' ProtonVPN restores normalcy (and the 'original' ProtonVPN entry disappears). This seems to be a well documented issue that is easily fixed in the GUI, but I run a script that reboots qBittorrent daily so I am running into it a lot. In the most recent incidence of this problem, the following appears in qBittorrent.log: > (C) 2025-08-13T05:00:30 - The configured network interface is invalid. Interface: "iftype53_32768" I then selected the 'other' ProtonVPN from the dropdown and looked at qbittorrent.ini. The interface now shows up as > Session\Interface=iftype53_32769 I'm not entirely sure how to interpret this. I've confirmed the ProtonVPN client has not updated from before to after this error occurs, however it is configured to connect to a random server on each startup. As a workaround, does anyone know how I can determine from qBittorrent's settings files which of these iftype53 values is correct (i.e. is there a way I can programmatically identify what the Session\Interface value should be for the 'other' ProtonVPN entry, seeing as both appear as Session\InterfaceName=ProtonVPN)? Worth noting I did also have this problem with NordVPN occasionally so I don't think it is Proton that is the issue (or if it is then NordVPN is affected by the same problem) Thanks in advance! ### Steps to reproduce This issue happens after qBittorrent is rebooted. I also restart my VPN simultaneously via script and the problem only occurs intermittently so I am not sure how to reproduce ### Additional context _No response_ ### Log(s) & preferences file(s) [qBittorrent.txt](https://github.com/user-attachments/files/21768833/qBittorrent.txt) [qbittorrent.log](https://github.com/user-attachments/files/21768825/qbittorrent.log)
Author
Owner

@lw4242 commented on GitHub (Aug 14, 2025):

Ok so it seems to be to do with the adapter token being renamed when Windows re-enumerates it for whatever reason. I (well, mostly AI) wrote some Python code to get and set the correct token into qBittorrent.ini (Session\Interface=XXXXXXXXX). When run before starting qBittorrent this should fix the problem, but it won't fix the problem if it happens while qBittorrent is running. Note also that qB appears to rewrite the loaded configuration file on close so qB needs to be closed when this snippet of code is run.

Furthermore if you close qBittorrent and set Session\Interface to something invalid it will reproduceably cause the fault with two ProtonVPN entries appearing in the dropdown, and then if you close qB, run this script and then re-open qB it will reproduceably correct the problem.

import ctypes
from ctypes import wintypes
import subprocess
import re

ENFORCE_VPN_BINDING = True
VPN_INTERFACE_FRIENDLY_NAME = "ProtonVPN"
QBIT_CONFIG = r"C:\Users\Plex\AppData\Roaming\qBittorrent\qBittorrent.ini"

# ---- Adapter token helpers ----
class NET_LUID_LH(ctypes.Structure):
    _fields_ = [("Value", ctypes.c_ulonglong)]

iphlpapi = ctypes.WinDLL("iphlpapi")
ConvertInterfaceIndexToLuid = iphlpapi.ConvertInterfaceIndexToLuid
ConvertInterfaceIndexToLuid.argtypes = [wintypes.ULONG, ctypes.POINTER(NET_LUID_LH)]
ConvertInterfaceIndexToLuid.restype = wintypes.ULONG

def luid_token_from_index(idx: int):
    luid = NET_LUID_LH(0)
    ret = ConvertInterfaceIndexToLuid(idx, ctypes.byref(luid))
    if ret != 0:
        return None
    val = int(luid.Value)
    iftype = (val >> 48) & 0xFFFF
    netluid_index = (val >> 24) & 0xFFFFFF
    return f"iftype{iftype}_{netluid_index}"

def get_adapter_token_by_name(name_substring):
    proc = subprocess.run(
        ["netsh", "interface", "ipv4", "show", "interfaces"],
        capture_output=True, text=True, check=True
    )
    rx = re.compile(r"^\s*(\d+)\s+\d+\s+\d+\s+\S+\s+(.*\S)\s*$")
    for line in proc.stdout.splitlines():
        m = rx.match(line)
        if m:
            idx = int(m.group(1))
            name = m.group(2)
            if name_substring.lower() in name.lower():
                return luid_token_from_index(idx)
    return None

# ---- Config enforcement ----
def enforce_vpn_binding():
    if not ENFORCE_VPN_BINDING:
        return

    token = get_adapter_token_by_name(VPN_INTERFACE_FRIENDLY_NAME)
    if token:
        print("Current adapter token:", token)
    else:
        print("VPN adapter not found.")
        return

    keep_key_name = "Session\\InterfaceName"
    keep_key_token = "Session\\Interface"
    drop_prefixes = (
        "Session\\InterfaceId=",
        "Session\\InterfaceAddress=",
    )
    desired_name_line = f"{keep_key_name}={VPN_INTERFACE_FRIENDLY_NAME}\n"
    desired_token_line = f"{keep_key_token}={token}\n"

    with open(QBIT_CONFIG, "r", encoding="utf-8", errors="ignore") as f:
        lines = f.readlines()

    out = []
    have_bt = False
    have_name = False
    have_token = False

    for line in lines:
        s = line.strip()
        if s.lower() == "[bittorrent]":
            have_bt = True
            out.append(line)
            continue
        if s.startswith(keep_key_name + "="):
            out.append(desired_name_line)  # normalize
            have_name = True
            continue
        if s.startswith(keep_key_token + "="):
            out.append(desired_token_line)  # normalize
            have_token = True
            continue
        if any(s.startswith(p) for p in drop_prefixes):
            continue  # remove unwanted volatile keys
        out.append(line)

    # Insert missing keys under [BitTorrent]
    if not have_name or not have_token:
        if not have_bt:
            out.append("[BitTorrent]\n")
            have_bt = True
        if not have_name:
            out.append(desired_name_line)
        if not have_token:
            out.append(desired_token_line)

    with open(QBIT_CONFIG, "w", encoding="utf-8") as f:
        f.writelines(out)

# Example call
enforce_vpn_binding()

@lw4242 commented on GitHub (Aug 14, 2025): Ok so it seems to be to do with the adapter token being renamed when Windows re-enumerates it for whatever reason. I (well, mostly AI) wrote some Python code to get and set the correct token into qBittorrent.ini (Session\Interface=XXXXXXXXX). When run before starting qBittorrent this should fix the problem, but it won't fix the problem if it happens while qBittorrent is running. Note also that qB appears to rewrite the loaded configuration file on close so qB needs to be closed when this snippet of code is run. Furthermore if you close qBittorrent and set Session\Interface to something invalid it will reproduceably cause the fault with two ProtonVPN entries appearing in the dropdown, and then if you close qB, run this script and then re-open qB it will reproduceably correct the problem. ``` import ctypes from ctypes import wintypes import subprocess import re ENFORCE_VPN_BINDING = True VPN_INTERFACE_FRIENDLY_NAME = "ProtonVPN" QBIT_CONFIG = r"C:\Users\Plex\AppData\Roaming\qBittorrent\qBittorrent.ini" # ---- Adapter token helpers ---- class NET_LUID_LH(ctypes.Structure): _fields_ = [("Value", ctypes.c_ulonglong)] iphlpapi = ctypes.WinDLL("iphlpapi") ConvertInterfaceIndexToLuid = iphlpapi.ConvertInterfaceIndexToLuid ConvertInterfaceIndexToLuid.argtypes = [wintypes.ULONG, ctypes.POINTER(NET_LUID_LH)] ConvertInterfaceIndexToLuid.restype = wintypes.ULONG def luid_token_from_index(idx: int): luid = NET_LUID_LH(0) ret = ConvertInterfaceIndexToLuid(idx, ctypes.byref(luid)) if ret != 0: return None val = int(luid.Value) iftype = (val >> 48) & 0xFFFF netluid_index = (val >> 24) & 0xFFFFFF return f"iftype{iftype}_{netluid_index}" def get_adapter_token_by_name(name_substring): proc = subprocess.run( ["netsh", "interface", "ipv4", "show", "interfaces"], capture_output=True, text=True, check=True ) rx = re.compile(r"^\s*(\d+)\s+\d+\s+\d+\s+\S+\s+(.*\S)\s*$") for line in proc.stdout.splitlines(): m = rx.match(line) if m: idx = int(m.group(1)) name = m.group(2) if name_substring.lower() in name.lower(): return luid_token_from_index(idx) return None # ---- Config enforcement ---- def enforce_vpn_binding(): if not ENFORCE_VPN_BINDING: return token = get_adapter_token_by_name(VPN_INTERFACE_FRIENDLY_NAME) if token: print("Current adapter token:", token) else: print("VPN adapter not found.") return keep_key_name = "Session\\InterfaceName" keep_key_token = "Session\\Interface" drop_prefixes = ( "Session\\InterfaceId=", "Session\\InterfaceAddress=", ) desired_name_line = f"{keep_key_name}={VPN_INTERFACE_FRIENDLY_NAME}\n" desired_token_line = f"{keep_key_token}={token}\n" with open(QBIT_CONFIG, "r", encoding="utf-8", errors="ignore") as f: lines = f.readlines() out = [] have_bt = False have_name = False have_token = False for line in lines: s = line.strip() if s.lower() == "[bittorrent]": have_bt = True out.append(line) continue if s.startswith(keep_key_name + "="): out.append(desired_name_line) # normalize have_name = True continue if s.startswith(keep_key_token + "="): out.append(desired_token_line) # normalize have_token = True continue if any(s.startswith(p) for p in drop_prefixes): continue # remove unwanted volatile keys out.append(line) # Insert missing keys under [BitTorrent] if not have_name or not have_token: if not have_bt: out.append("[BitTorrent]\n") have_bt = True if not have_name: out.append(desired_name_line) if not have_token: out.append(desired_token_line) with open(QBIT_CONFIG, "w", encoding="utf-8") as f: f.writelines(out) # Example call enforce_vpn_binding() ```
Author
Owner

@freonpsandoz commented on GitHub (Nov 8, 2025):

For those who aren't Python programmers, is there a simple way in powershell to put the correct value of Session\Interface in qBittorrent.ini? I manually replaced the "iftype53_32769" value in the ini file with the value "iftype53_32768" obtained from the powershell command "Get-NetAdapter | Format-List -Property *" and this worked.

I have also been able to correct the problem from inside qB by changing the network interface to "any interface" and then changing it back to the desired VPN interface.

I notice that Session\InterfaceName in the ini file is correct. Would it be possible for qB to use that name if Session\Interface is invalid?

@freonpsandoz commented on GitHub (Nov 8, 2025): For those who aren't Python programmers, is there a simple way in powershell to put the correct value of Session\Interface in qBittorrent.ini? I manually replaced the "iftype53_32769" value in the ini file with the value "iftype53_32768" obtained from the powershell command "Get-NetAdapter | Format-List -Property *" and this worked. I have also been able to correct the problem from inside qB by changing the network interface to "any interface" and then changing it back to the desired VPN interface. I notice that Session\InterfaceName in the ini file is correct. Would it be possible for qB to use that name if Session\Interface is invalid?
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/qBittorrent#17076
No description provided.