Created
February 15, 2010 18:56
-
-
Save briandoll/304882 to your computer and use it in GitHub Desktop.
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
# 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