Page 1 of 1

Disconnect a VPN user using RPC API

Posted: Wed Jun 21, 2023 12:45 pm
by tpot
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)

Re: Disconnect a VPN user using RPC API

Posted: Wed Jun 21, 2023 7:28 pm
by solo
  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