summaryrefslogtreecommitdiffhomepage
path: root/demos/demo_simple.py
diff options
context:
space:
mode:
Diffstat (limited to 'demos/demo_simple.py')
-rwxr-xr-xdemos/demo_simple.py45
1 files changed, 32 insertions, 13 deletions
diff --git a/demos/demo_simple.py b/demos/demo_simple.py
index 50f344a7..3a17988c 100755
--- a/demos/demo_simple.py
+++ b/demos/demo_simple.py
@@ -25,13 +25,21 @@ import os
import socket
import sys
import traceback
+from paramiko.py3compat import input
import paramiko
-import interactive
+try:
+ import interactive
+except ImportError:
+ from . import interactive
# setup logging
paramiko.util.log_to_file('demo_simple.log')
+# Paramiko client configuration
+UseGSSAPI = True # enable GSS-API / SSPI authentication
+DoGSSAPIKeyExchange = True
+port = 22
# get hostname
username = ''
@@ -40,11 +48,11 @@ if len(sys.argv) > 1:
if hostname.find('@') >= 0:
username, hostname = hostname.split('@')
else:
- hostname = raw_input('Hostname: ')
+ hostname = input('Hostname: ')
if len(hostname) == 0:
- print '*** Hostname required.'
+ print('*** Hostname required.')
sys.exit(1)
-port = 22
+
if hostname.find(':') >= 0:
hostname, portstr = hostname.split(':')
port = int(portstr)
@@ -53,10 +61,11 @@ if hostname.find(':') >= 0:
# get username
if username == '':
default_username = getpass.getuser()
- username = raw_input('Username [%s]: ' % default_username)
+ username = input('Username [%s]: ' % default_username)
if len(username) == 0:
username = default_username
-password = getpass.getpass('Password for %s@%s: ' % (username, hostname))
+if not UseGSSAPI or (not UseGSSAPI and not DoGSSAPIKeyExchange):
+ password = getpass.getpass('Password for %s@%s: ' % (username, hostname))
# now, connect and use paramiko Client to negotiate SSH2 across the connection
@@ -64,18 +73,28 @@ try:
client = paramiko.SSHClient()
client.load_system_host_keys()
client.set_missing_host_key_policy(paramiko.WarningPolicy())
- print '*** Connecting...'
- client.connect(hostname, port, username, password)
+ print('*** Connecting...')
+ if not UseGSSAPI or (not UseGSSAPI and not DoGSSAPIKeyExchange):
+ client.connect(hostname, port, username, password)
+ else:
+ # SSPI works only with the FQDN of the target host
+ hostname = socket.getfqdn(hostname)
+ try:
+ client.connect(hostname, port, username, gss_auth=UseGSSAPI,
+ gss_kex=DoGSSAPIKeyExchange)
+ except Exception:
+ password = getpass.getpass('Password for %s@%s: ' % (username, hostname))
+ client.connect(hostname, port, username, password)
+
chan = client.invoke_shell()
- print repr(client.get_transport())
- print '*** Here we go!'
- print
+ print(repr(client.get_transport()))
+ print('*** Here we go!\n')
interactive.interactive_shell(chan)
chan.close()
client.close()
-except Exception, e:
- print '*** Caught exception: %s: %s' % (e.__class__, e)
+except Exception as e:
+ print('*** Caught exception: %s: %s' % (e.__class__, e))
traceback.print_exc()
try:
client.close()