Created
May 21, 2014 13:25
-
-
Save redperadot/c40e3df96e953a6f539f to your computer and use it in GitHub Desktop.
Revisions
-
Cody Hannafon created this gist
May 21, 2014 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,62 @@ #!/usr/bin/env ruby # # grsp.rb - Get remote OS X system profile. Version 0.1 # Made with ❤︎ by [email protected] require 'optparse' require 'io/console' require 'net/ssh' Signal.trap("INT") { puts; exit 0 } options = {} OptionParser.new do |opts| opts.banner = "Usage: #{$0} [flag]" opts.on("-h", "--host HOSTNAME", "The remote host to get the report from.") do |hn| @host = hn end opts.on("-u", "--user USERNAME", "The user to log into the remote host.") do |un| @user = un end opts.on("-p", "--pass PASSWORD", "The password to log into the remote host.") do |pw| @pass = pw end opts.on("-o", "--out OUTFILE", "The path to save the report.") do |of| @file = of end end.parse! @host ||= (print 'Hostname: '; gets.chomp) @user ||= (print 'Username: '; gets.chomp) @pass ||= (print 'Password: '; $stdin.noecho(&:gets).chomp) @file ||= File.expand_path("~/#{@host}.spx") puts puts puts 'Config:' puts ' Hostname - ' + @host puts ' Username - ' + @user puts ' Password - ' + '*' * @pass.length puts ' Out File - ' + @file puts puts "[Info] Accessing '#{@host}'." begin Net::SSH.start(@host, @user, :password => @pass) do |ssh| puts "[Info] Waiting for '#{@host}' to generate report." data = ssh.exec!('system_profiler -xml -detailLevel full 2> /dev/null') puts "[Info] Writing report to local file, at '#{@file}'." File.open(@file, 'w') { |f| f.puts data } end rescue SocketError abort('[Error] Could not reach the host.') rescue Timeout::Error abort('[Error] The connection timed out.') rescue Errno::EHOSTUNREACH abort('[Error] Could not reach the host.') rescue Errno::ECONNREFUSED abort('[Error] The connection to the host was refused.') rescue Net::SSH::AuthenticationFailed abort('[Error] Authentication with the host failed.') rescue Exception abort('[Error] An unknown error occurred.') end