diff options
Diffstat (limited to 'examples/passmass.py')
-rwxr-xr-x | examples/passmass.py | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/examples/passmass.py b/examples/passmass.py index 4c4c850..f5bd04b 100755 --- a/examples/passmass.py +++ b/examples/passmass.py @@ -22,6 +22,10 @@ PEXPECT LICENSE ''' +from __future__ import print_function + +from __future__ import absolute_import + import pexpect import sys, getpass @@ -39,9 +43,9 @@ def login(host, user, password): i = child.expect([pexpect.TIMEOUT, SSH_NEWKEY, '[Pp]assword: ']) if i == 0: # Timeout - print 'ERROR!' - print 'SSH could not login. Here is what SSH said:' - print child.before, child.after + print('ERROR!') + print('SSH could not login. Here is what SSH said:') + print(child.before, child.after) sys.exit (1) if i == 1: # SSH does not have the public key. Just accept it. child.sendline ('yes') @@ -51,7 +55,7 @@ def login(host, user, password): # the login process is asking for our terminal type. i = child.expect (['Permission denied', TERMINAL_PROMPT, COMMAND_PROMPT]) if i == 0: - print 'Permission denied on host:', host + print('Permission denied on host:', host) sys.exit (1) if i == 1: child.sendline (TERMINAL_TYPE) @@ -70,8 +74,8 @@ def change_password(child, user, oldpassword, newpassword): child.sendline(newpassword) i = child.expect(['[Nn]ew [Pp]assword', '[Rr]etype', '[Rr]e-enter']) if i == 0: - print 'Host did not like new password. Here is what it said...' - print child.before + print('Host did not like new password. Here is what it said...') + print(child.before) child.send (chr(3)) # Ctrl-C child.sendline('') # This should tell remote passwd command to quit. return @@ -80,7 +84,7 @@ def change_password(child, user, oldpassword, newpassword): def main(): if len(sys.argv) <= 1: - print USAGE + print(USAGE) return 1 user = raw_input('Username: ') @@ -88,15 +92,15 @@ def main(): newpassword = getpass.getpass('New Password: ') newpasswordconfirm = getpass.getpass('Confirm New Password: ') if newpassword != newpasswordconfirm: - print 'New Passwords do not match.' + print('New Passwords do not match.') return 1 for host in sys.argv[1:]: child = login(host, user, password) if child == None: - print 'Could not login to host:', host + print('Could not login to host:', host) continue - print 'Changing password on host:', host + print('Changing password on host:', host) change_password(child, user, password, newpassword) child.expect(COMMAND_PROMPT) child.sendline('exit') @@ -104,5 +108,5 @@ def main(): if __name__ == '__main__': try: main() - except pexpect.ExceptionPexpect, e: - print str(e) + except pexpect.ExceptionPexpect as e: + print(str(e)) |