#!/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')