Disconnect a VPN user using RPC API
Posted: 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)
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)