Created
April 19, 2015 18:01
-
-
Save arbinish/37b60e56cadbef7a2ebb to your computer and use it in GitHub Desktop.
Password automation
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
# coding: utf-8 | |
import pty | |
import os | |
import sys | |
commands = ["some-command", "--with", "options"] | |
pid, child_fd = pty.fork() | |
if not pid: | |
os.execv(commands[0], commands) | |
# you may use getpass here | |
password = "secRetPa33w0rd" | |
while True: | |
try: | |
output = os.read(child_fd, 1024).strip() | |
except OSError: | |
break | |
# the following two lines are not really necessary though | |
sys.stdout.write("output: %s\n" % output) | |
sys.stdout.flush() | |
lower = output.lower() | |
if lower.endswith("password:"): | |
os.write(child_fd, "%s\n" % password) | |
elif 'are you sure' in lower: | |
os.write(child_fd, "y\n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment