Fix print statements
This commit is contained in:
parent
e5822c9fa1
commit
f73d5f73e5
|
@ -45,13 +45,13 @@ def agent_auth(transport, username):
|
||||||
return
|
return
|
||||||
|
|
||||||
for key in agent_keys:
|
for key in agent_keys:
|
||||||
print 'Trying ssh-agent key %s' % hexlify(key.get_fingerprint()),
|
print('Trying ssh-agent key %s' % hexlify(key.get_fingerprint()))
|
||||||
try:
|
try:
|
||||||
transport.auth_publickey(username, key)
|
transport.auth_publickey(username, key)
|
||||||
print '... success!'
|
print('... success!')
|
||||||
return
|
return
|
||||||
except paramiko.SSHException:
|
except paramiko.SSHException:
|
||||||
print '... nope.'
|
print('... nope.')
|
||||||
|
|
||||||
|
|
||||||
def manual_auth(username, hostname):
|
def manual_auth(username, hostname):
|
||||||
|
@ -98,7 +98,7 @@ if len(sys.argv) > 1:
|
||||||
else:
|
else:
|
||||||
hostname = raw_input('Hostname: ')
|
hostname = raw_input('Hostname: ')
|
||||||
if len(hostname) == 0:
|
if len(hostname) == 0:
|
||||||
print '*** Hostname required.'
|
print('*** Hostname required.')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
port = 22
|
port = 22
|
||||||
if hostname.find(':') >= 0:
|
if hostname.find(':') >= 0:
|
||||||
|
@ -111,6 +111,7 @@ try:
|
||||||
sock.connect((hostname, port))
|
sock.connect((hostname, port))
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
print '*** Connect failed: ' + str(e)
|
print '*** Connect failed: ' + str(e)
|
||||||
|
print('*** Connect failed: ' + str(e))
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
@ -119,7 +120,7 @@ try:
|
||||||
try:
|
try:
|
||||||
t.start_client()
|
t.start_client()
|
||||||
except paramiko.SSHException:
|
except paramiko.SSHException:
|
||||||
print '*** SSH negotiation failed.'
|
print('*** SSH negotiation failed.')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -128,20 +129,20 @@ try:
|
||||||
try:
|
try:
|
||||||
keys = paramiko.util.load_host_keys(os.path.expanduser('~/ssh/known_hosts'))
|
keys = paramiko.util.load_host_keys(os.path.expanduser('~/ssh/known_hosts'))
|
||||||
except IOError:
|
except IOError:
|
||||||
print '*** Unable to open host keys file'
|
print('*** Unable to open host keys file')
|
||||||
keys = {}
|
keys = {}
|
||||||
|
|
||||||
# check server's host key -- this is important.
|
# check server's host key -- this is important.
|
||||||
key = t.get_remote_server_key()
|
key = t.get_remote_server_key()
|
||||||
if not keys.has_key(hostname):
|
if hostname not in keys:
|
||||||
print '*** WARNING: Unknown host key!'
|
print('*** WARNING: Unknown host key!')
|
||||||
elif not keys[hostname].has_key(key.get_name()):
|
elif key.get_name() not in keys[hostname]:
|
||||||
print '*** WARNING: Unknown host key!'
|
print('*** WARNING: Unknown host key!')
|
||||||
elif keys[hostname][key.get_name()] != key:
|
elif keys[hostname][key.get_name()] != key:
|
||||||
print '*** WARNING: Host key has changed!!!'
|
print('*** WARNING: Host key has changed!!!')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
else:
|
else:
|
||||||
print '*** Host key OK.'
|
print('*** Host key OK.')
|
||||||
|
|
||||||
# get username
|
# get username
|
||||||
if username == '':
|
if username == '':
|
||||||
|
@ -154,21 +155,21 @@ try:
|
||||||
if not t.is_authenticated():
|
if not t.is_authenticated():
|
||||||
manual_auth(username, hostname)
|
manual_auth(username, hostname)
|
||||||
if not t.is_authenticated():
|
if not t.is_authenticated():
|
||||||
print '*** Authentication failed. :('
|
print('*** Authentication failed. :(')
|
||||||
t.close()
|
t.close()
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
chan = t.open_session()
|
chan = t.open_session()
|
||||||
chan.get_pty()
|
chan.get_pty()
|
||||||
chan.invoke_shell()
|
chan.invoke_shell()
|
||||||
print '*** Here we go!'
|
print('*** Here we go!\n')
|
||||||
print
|
|
||||||
interactive.interactive_shell(chan)
|
interactive.interactive_shell(chan)
|
||||||
chan.close()
|
chan.close()
|
||||||
t.close()
|
t.close()
|
||||||
|
|
||||||
except Exception, e:
|
except Exception:
|
||||||
print '*** Caught exception: ' + str(e.__class__) + ': ' + str(e)
|
e = sys.exc_info()[1]
|
||||||
|
print('*** Caught exception: ' + str(e.__class__) + ': ' + str(e))
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
try:
|
try:
|
||||||
t.close()
|
t.close()
|
||||||
|
|
|
@ -51,7 +51,7 @@ def posix_shell(chan):
|
||||||
try:
|
try:
|
||||||
x = chan.recv(1024)
|
x = chan.recv(1024)
|
||||||
if len(x) == 0:
|
if len(x) == 0:
|
||||||
print '\r\n*** EOF\r\n',
|
sys.stdout.write('\r\n*** EOF\r\n')
|
||||||
break
|
break
|
||||||
sys.stdout.write(x)
|
sys.stdout.write(x)
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
|
|
Loading…
Reference in New Issue