GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — ssh2-python/examples/keyboard_interactive_auth.py at buffer_write · 7Learnings/ssh2-python Expand file tree/ Copy pathkeyboard_interactive_auth.pyMore file actions 61 lines (43 loc) · 1.63 KB / Copy pathkeyboard_interactive_auth.pyFile metadata and controls61 lines (43 loc) · 1.63 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 #!/usr/bin/python """Example script for authentication with Python callback function using an OAuth token""" from __future__ import print_function import argparse import socket import os import pwd import functools from ssh2.session import Session USERNAME = pwd.getpwuid(os.geteuid()).pw_name parser = argparse.ArgumentParser() parser.add_argument('password', help="User password") parser.add_argument('oauth', help="OAUTH key to use for authentication") parser.add_argument('cmd', help="Command to run") parser.add_argument('--host', dest='host', default='localhost', help='Host to connect to') parser.add_argument('--port', dest='port', default=22, help="Port to connect on", type=int) parser.add_argument('-u', dest='user', default=USERNAME, help="User name to authenticate as") def oauth_handler(name, instruction, prompts, password, oauth): responses = [] for prompt in prompts: if "Password:" in prompt: responses.append(password) if "One-time password (OATH) for" in prompt: responses.append(oauth) return responses def main(): args = parser.parse_args() callback = functools.partial(oauth_handler,password=args.password,oauth=args.oauth) sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect((args.host, args.port)) s = Session() s.handshake(sock) s.userauth_keyboardinteractive_callback(args.user, callback) chan = s.open_session() chan.execute(args.cmd) size, data = chan.read() while size > 0: print(data) size, data = chan.read() if __name__ == "__main__": main() |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |