@@ -8,6 +8,7 @@ require 'netaddr'
8
8
require 'optparse'
9
9
require 'ssh_scan'
10
10
require 'logger'
11
+ require 'yaml'
11
12
12
13
#Default options
13
14
options = {
@@ -18,7 +19,8 @@ options = {
18
19
"threads" => 5 ,
19
20
"verbosity" => nil ,
20
21
"logger" => Logger . new ( STDERR ) ,
21
- "fingerprint_database" => ENV [ 'HOME' ] +'/.ssh_scan_fingerprints.yml'
22
+ "fingerprint_database" => ENV [ 'HOME' ] +'/.ssh_scan_fingerprints.yml' ,
23
+ "output_type" => "json"
22
24
}
23
25
24
26
# Reorder arguments before parsing
@@ -107,6 +109,11 @@ scan") do |file|
107
109
$stdout. reopen ( file , "w" )
108
110
end
109
111
112
+ opts . on ( "--output-type [json, yaml]" ,
113
+ "Format to write stdout to json or yaml" ) do |output_type |
114
+ options [ "output_type" ] = output_type
115
+ end
116
+
110
117
opts . on ( "-p" , "--port [PORT]" , Array ,
111
118
"Port (Default: 22)" ) do |ports |
112
119
temp = [ ]
@@ -225,39 +232,17 @@ unless File.exist?(options["policy"])
225
232
exit 1
226
233
end
227
234
228
- # Check to see if we're running the latest released version
229
- #if !options["suppress_update_status"]
230
- # update = SSHScan::Update.new
231
- # if update.newer_gem_available?
232
- # options["logger"].warn(
233
- # "You're NOT using the latest version of ssh_scan, try 'gem update \
234
- #ssh_scan' to get the latest"
235
- # )
236
- # else
237
- # if update.errors.any?
238
- # update.errors.each do |error|
239
- # options["logger"].error(error)
240
- # end
241
- # else
242
- # options["logger"].info(
243
- # "You're using the latest version of ssh_scan #{SSHScan::VERSION}"
244
- # )
245
- # end
246
- # end
247
- #end
248
-
249
- # Limit scope of fingerprints DB to (per scan)
250
- # if options["fingerprint_database"] && File.exists?(options["fingerprint_database"])
251
- # File.unlink(options["fingerprint_database"])
252
- # end
253
-
254
235
options [ "policy_file" ] = SSHScan ::Policy . from_file ( options [ "policy" ] )
255
236
256
237
# Perform scan and get results
257
238
scan_engine = SSHScan ::ScanEngine . new ( )
258
239
results = scan_engine . scan ( options )
259
240
260
- puts JSON . pretty_generate ( results )
241
+ if options [ "output_type" ] == "yaml"
242
+ puts YAML . dump ( results )
243
+ elsif options [ "output_type" ] == "json"
244
+ puts JSON . pretty_generate ( results )
245
+ end
261
246
262
247
if options [ "unit_test" ] == true
263
248
results . each do |result |
0 commit comments