Disconnect a VPN user using RPC API

Post your questions about SoftEther VPN software here. Please answer questions if you can afford.
Post Reply
tpot
Posts: 1
Joined: Wed Jun 21, 2023 12:25 pm

Disconnect a VPN user using RPC API

Post by tpot » Wed Jun 21, 2023 12:45 pm

Hi,

I have been trying to use the below remote python API to disconnect a user from the VPN but I get the message it's been unsuccessful when disconnecting the user.

Error: Failed to disconnect user 'xxx' from hub 'vpn'.

Has anyone been successful in doing this ?

Here's my Python code below:

import requests
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

def disconnect_user(host, port, admin_password, hub_name, username):
# Create the URL for the API endpoint
url = "https://{}:{}/api".format(host, port)

# Define the API parameters
params = {
'AdminPassword': admin_password,
'API': 'DisconnectSession',
'AccountName': username,
'HubName': hub_name
}

# Send the API request
response = requests.get(url, params=params, verify=False)

# Check the response status code
if response.status_code == 200:
print("User '{}' disconnected successfully from hub '{}'.".format(username, hub_name))
else:
print("Failed to disconnect user '{}' from hub '{}'.".format(username, hub_name))

# Usage example
host = 'ip address' # SoftEther VPN Server IP address
port = 'port' # SoftEther VPN Server Management Port
admin_password = 'password'
hub_name = 'vpn'
username = 'xxx'

disconnect_user(host, port, admin_password, hub_name, username)

solo
Posts: 1286
Joined: Sun Feb 14, 2021 10:31 am

Re: Disconnect a VPN user using RPC API

Post by solo » Wed Jun 21, 2023 7:28 pm

  1. EnumSession like eg https://www.vpnusers.com/viewtopic.php? ... 563#p98563
  2. then pipe it to jq https://stedolan.github.io/jq/ to select session with a user
  3. and finally DeleteSession of the user

Post Reply