Skip to content

Instantly share code, notes, and snippets.

@gnachman
Created June 13, 2016 22:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gnachman/846f3181549c8b172284efeea1e85bfd to your computer and use it in GitHub Desktop.
Save gnachman/846f3181549c8b172284efeea1e85bfd to your computer and use it in GitHub Desktop.
#!/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