fork download
  1. import paramiko
  2.  
  3. # Set up the SSH client object
  4. client = paramiko.SSHClient()
  5. client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  6.  
  7. # Define the connection parameters
  8. hostname = '172.17.216.128'
  9. port = 22
  10. username = 'usr2'
  11. password = ' '
  12. # Connect to the server
  13. client.connect(hostname, port=port, username=username, password=password)
  14.  
  15. # Prompt the user for their DUO passcode
  16. duo_passcode = input("Enter your DUO passcode: ")
  17.  
  18. # Invoke the authentication method on the server using the provided passcode
  19. stdin, stdout, stderr = client.exec_command('duo_unix -check {0}'.format(duo_passcode))
  20.  
  21. # Check the response from the server to see if authentication was successful
  22. if 'status=allow' in stdout.read().decode('utf-8'):
  23. print("Authentication successful!")
  24. # Perform other tasks on the server as needed
  25. else:
  26. print("Authentication failed. Please try again.")
  27.  
  28. # Close the connection to the server
  29. client.close()
  30.  
Success #stdin #stdout #stderr 0.02s 6984KB
stdin
1
2
10
42
11
stdout
Standard output is empty
stderr
ERROR: /home/ghffjn/prog:29:14: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit