0

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
asked Jul 3, 2025 at 14:47
1
  • Maybe try process.communicate(input=opt_command). Commented Jul 3, 2025 at 15:03

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.