I'm attempting to build a script that I can use to connect to my SonicWall NetExtender VPN via Python.
Currently my connect method successfully triggers the OTP password to be sent to my email.
def connect(self, server, username, password, domain):
# Define the command to run the VPN connection
command = f'"{self.necli_path}" connect -s {server} -u {username} -p {password} -d {domain}'
# Start the process
self.process = subprocess.Popen(
command,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=True,
text=True
)
but when I try to simulate the entering of the OTP in my submit_otp method, nothing happens:
def submit_otp(self, otp):
if self.process is None:
return False, "Error: The VPN process has not been initialized."
# Check if process.stdin is still open
if self.process.stdin.closed:
return False, "Error: The process stdin stream has been closed."
# Send the OTP after VPN prompts for it
otp_command = otp + "\n" # Simulate pressing "Enter" after OTP
self.process.stdin.write(otp_command)
self.process.stdin.flush()
return True, None
Any help is greatly appreciated, TiA!
Emi OB
3,4373 gold badges20 silver badges40 bronze badges
lang-py
process.communicate(input=opt_command).