Created
June 13, 2016 22:22
-
-
Save gnachman/846f3181549c8b172284efeea1e85bfd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import re | |
import sys | |
import os | |
def ReadUntilPrefix(prefix): | |
k = 0 | |
buff = '' | |
while True: | |
buff += sys.stdin.read(1) | |
if buff.endswith('\n') or buff.endswith('\r'): | |
return buff[:-1] | |
buff = '' | |
k = k + 1 | |
elif buff.startswith(prefix): | |
return buff | |
host = None | |
passwords = { "host1": "password1", "host2": "Password2" } | |
while True: | |
line = ReadUntilPrefix("Password:") | |
if len(line) == 0: | |
continue | |
m = re.search(r".*ssh user@([^ ]*)", line) | |
if m: | |
host = m.groups()[0] | |
elif line == "Password:": | |
sys.stdout.flush() | |
if passwords.has_key(host): | |
print passwords[host] | |
host = None | |
else: | |
host = None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment