Class: Ronin::Masscan::CLI::Commands::Convert Private

Inherits:
Ronin::Masscan::CLI::Command show all
Defined in:
lib/ronin/masscan/cli/commands/convert.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Converts an masscan scan file to JSON or CSV.

Usage

ronin-masscan convert [options] INPUT_FILE [OUTPUT_FILE]

Option

-I binary|list|json|ndjson,      The input format
    --input-format
-F, --format json|csv            The desired output format
-h, --help                       Print help information

Arguments

INPUT_FILE                       The input masscan scan file to parse
OUTPUT_FILE                      The output file

Instance Method Summary collapse

Instance Method Details

#open_masscan_file(path) ⇒ ::Masscan::OutputFile

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Opens a masscan scan file.

Parameters:

  • path (String)

    The path to the masscan scan file.

Returns:

  • (::Masscan::OutputFile)

    The opened masscan scan file.



118
119
120
121
122
123
124
125
126
127
# File 'lib/ronin/masscan/cli/commands/convert.rb', line 118

def open_masscan_file(path)
  if options[:input_format]
    ::Masscan::OutputFile.new(path, format: options[:input_format])
  else
    ::Masscan::OutputFile.new(path)
  end
rescue ArgumentError => error
  print_error(error.message)
  exit(1)
end

#run(input_file, output_file = nil) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Runs the ronin-masscan convert command.

Parameters:

  • input_file (String)

    The masscan scan file to parse.

  • output_file (String) (defaults to: nil)

    The output file to write to.



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/ronin/masscan/cli/commands/convert.rb', line 83

def run(input_file,output_file=nil)
  unless File.file?(input_file)
    print_error "no such file or directory: #{input_file}"
    exit(-1)
  end

  masscan_file = open_masscan_file(input_file)

  if output_file
    format = options.fetch(:format) do
               Converter.infer_format_for(output_file)
             end

    File.open(output_file,'w') do |output|
      Converter.convert(masscan_file,output, format: format)
    end
  else
    unless (format = options[:format])
      print_error "must specify a --format if no output file is given"
      exit(-1)
    end

    Converter.convert(masscan_file,stdout, format: format)
  end
end