Last active
April 25, 2016 12:23
-
-
Save oskaritimperi/3d86a44339baba2b66a9a23623576bab to your computer and use it in GitHub Desktop.
add all keys in a directory to pageant
This file contains hidden or 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
| import csv | |
| import os | |
| import subprocess | |
| import time | |
| KEYDIR = os.path.dirname(os.path.abspath(__file__)) | |
| PAGEANT_EXE = 'C:/tools/putty/pageant.exe' | |
| def running_processes(): | |
| s = subprocess.check_output(['tasklist.exe', '/fo', 'csv']).decode('cp437') | |
| lines = s.splitlines() | |
| return csv.reader(lines) | |
| def is_pageant_running(): | |
| for process in running_processes(): | |
| if process[0].lower().find('pageant') >= 0: | |
| return True | |
| return False | |
| def start_pageant(): | |
| if not is_pageant_running(): | |
| subprocess.Popen([PAGEANT_EXE]) | |
| time.sleep(0.5) | |
| def add_key(key): | |
| subprocess.call([PAGEANT_EXE, key]) | |
| if __name__ == '__main__': | |
| start_pageant() | |
| for filename in os.listdir(KEYDIR): | |
| filepath = os.path.join(KEYDIR, filename) | |
| if not os.path.isfile(filepath): | |
| continue | |
| if os.path.splitext(filepath)[1] != '.ppk': | |
| continue | |
| add_key(filepath) |
This file contains hidden or 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
| @echo off | |
| :: put this script in your Startup directory | |
| python D:\keys\pageant.py |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment