Skip to content

Instantly share code, notes, and snippets.

@briandoll
Created February 15, 2010 18:56
Show Gist options
  • Save briandoll/304882 to your computer and use it in GitHub Desktop.
Save briandoll/304882 to your computer and use it in GitHub Desktop.
# Ever forget the hostname of that server you logged into last week?
# Quickly get a chronological listing of hosts you've come to know...
require 'rubygems'
require 'net/ssh'
def who_do_i_know?
who = []
known_host_files = Net::SSH::KnownHosts.hostfiles({})
scanner = StringScanner.new("")
known_host_files.each do |host_file|
begin
File.open(File.expand_path(host_file)) do |file|
file.each_line do |line|
scanner.string = line
scanner.skip(/\s*/)
next if scanner.match?(/$|#/)
host_list = scanner.scan(/\S+/).split(/,/)
who << host_list[0]
end
end
rescue
end
end
who
end
puts who_do_i_know?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment