Created
May 23, 2019 11:22
-
-
Save walsvid/954d773f69b1140d53a0eea5e1f1b816 to your computer and use it in GitHub Desktop.
List my ssh server
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/env python | |
import sys | |
from termcolor import colored, cprint | |
with open('.ssh/config', 'r') as f: | |
for line in f: | |
l = line.strip() | |
#print('L', l) | |
if l.startswith('Host '): | |
record = {'Host':'','User':'','IP':''} | |
record['Host'] = l.split()[1] | |
while True: | |
try: | |
nex = next(f).strip() | |
if nex == '': | |
break | |
except StopIteration: | |
break | |
#nex = nex.strip() | |
if nex.startswith('HostName'): | |
record['IP'] = nex.split()[1] | |
if nex.startswith('User'): | |
record['User'] = nex.split()[1] | |
cprint('Server', end=' ') | |
cprint(record['Host'], 'green', attrs=['bold'], end=' ') | |
cprint('IP', end=' ') | |
cprint(record['IP'],'blue', attrs=['bold'], end=' ') | |
cprint('User', end=' ') | |
cprint(record['User'],'red', attrs=['bold'], end='\n') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment