Skip to content

Instantly share code, notes, and snippets.

@watsy0007
Created May 2, 2017 16:09
Show Gist options
  • Save watsy0007/68b67cdd8b4a057ae8adfcc3ae6ce1b0 to your computer and use it in GitHub Desktop.
Save watsy0007/68b67cdd8b4a057ae8adfcc3ae6ce1b0 to your computer and use it in GitHub Desktop.
ssh config hosts
import os.path, re
filename = os.path.expanduser("~/.ssh/config")
hosts = []
file = open(filename, 'rb')
contents = file.read()
for line in contents.split('\n\n'):
m = re.search('[Hh]ost\s+(?P<host_name>\w+)', line)
if m is not None:
hosts.append(m.group('host_name'))
hosts.sort()
print "\n".join(hosts)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment