Module: Ronin::Masscan::Converter
- Defined in:
- lib/ronin/masscan/converter.rb
Overview
Handles converting masscan scan file into other formats.
Supports the following formats:
- JSON
- CSV
Constant Summary collapse
- FILE_FORMATS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Mapping of file extension names to formats.
{ '.json' => :json, '.csv' => :csv }
Class Method Summary collapse
-
.convert(masscan_file, output = nil, format:) ⇒ IO, String
Converts parsed masscan scan file into the desired format.
-
.convert_file(src, dest, input_format: nil, format: infer_format_for(dest)) ⇒ Object
Converts an masscan scan file into another format.
-
.infer_format_for(path) ⇒ :json, :csv
private
Infers the output format from the output file's extension.
Class Method Details
.convert(masscan_file, output = nil, format:) ⇒ IO, String
Converts parsed masscan scan file into the desired format.
98 99 100 101 102 103 104 105 106 |
# File 'lib/ronin/masscan/converter.rb', line 98 def self.convert(masscan_file,output=nil, format: ) if output Converters[format].convert(masscan_file,output) else output = StringIO.new convert(masscan_file,output, format: format) output.string end end |
.convert_file(src, dest, input_format: nil, format: infer_format_for(dest)) ⇒ Object
Converts an masscan scan file into another format.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/ronin/masscan/converter.rb', line 66 def self.convert_file(src,dest, input_format: nil, format: infer_format_for(dest)) scan_file = if input_format ::Masscan::OutputFile.new(src, format: input_format) else ::Masscan::OutputFile.new(src) end converter = Converters[format] File.open(dest,'w') do |output| converter.convert(scan_file,output) end end |
.infer_format_for(path) ⇒ :json, :csv
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.
Infers the output format from the output file's extension.
122 123 124 125 126 |
# File 'lib/ronin/masscan/converter.rb', line 122 def self.infer_format_for(path) FILE_FORMATS.fetch(File.extname(path)) do raise(ArgumentError,"cannot infer output format from path: #{path.inspect}") end end |