Module: Ronin::Masscan::Converters::CSV Private

Defined in:
lib/ronin/masscan/converters/csv.rb

Overview

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

Handles converting masscan scan files into CSV.

Constant Summary collapse

HEADER =

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.

CSV rows header.

%w[type status.status status.protocol status.port status.reason status.ttl status.ip status.timestamp banner.protocol banner.port banner.ip banner.timestamp banner.app_protocol banner.payload]

Class Method Summary collapse

Class Method Details

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.



102
103
104
# File 'lib/ronin/masscan/converters/csv.rb', line 102

def self.banner_record_to_row(banner)
  ['banner', nil, nil, nil, nil, nil, nil, nil, banner.protocol, banner.port, banner.ip, banner.timestamp, banner.app_protocol, banner.payload]
end

.convert(masscan_file, output) ⇒ 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.

Converts the masscan scan file to CSV.

Parameters:

  • masscan_file (::Masscan::OutputFile)

    The opened masscan scan file.

  • output (StringIO, IO)

    Optional output stream to write the CSV to.



42
43
44
# File 'lib/ronin/masscan/converters/csv.rb', line 42

def self.convert(masscan_file,output)
  masscan_file_to_csv(masscan_file,output)
end

.masscan_file_to_csv(masscan_file, output) ⇒ 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.

Converts a masscan scan file to CSV.

Parameters:

  • masscan_file (::Masscan::OutputFile)

    The masscan scan file to convert to CSV.

  • output (StringIO, IO)

    The optional output to write the CSV to.



56
57
58
59
60
61
62
# File 'lib/ronin/masscan/converters/csv.rb', line 56

def self.masscan_file_to_csv(masscan_file,output)
  masscan_file_to_rows(masscan_file) do |row|
    output << ::CSV.generate_line(row)
  end

  return output
end

.masscan_file_to_rows(masscan_file) {|row| ... } ⇒ 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.

Converts an opened masscan scan file to a series of rows.

Parameters:

  • masscan_file (::Masscan::OutputFile)

    The opened masscan scan file.

Yields:

  • (row)

    The given block will be passed each row.

Yield Parameters:

  • row (Array)

    A row to be converted to CSV.



79
80
81
82
83
84
85
# File 'lib/ronin/masscan/converters/csv.rb', line 79

def self.masscan_file_to_rows(masscan_file)
  yield HEADER

  masscan_file.each do |record|
    yield record_to_row(record)
  end
end

.record_to_row(record) ⇒ 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.



87
88
89
90
91
92
93
94
95
96
# File 'lib/ronin/masscan/converters/csv.rb', line 87

def self.record_to_row(record)
  case record
  when ::Masscan::Status
    status_record_to_row(record)
  when ::Masscan::Banner
    banner_record_to_row(record)
  else
    raise(NotImplementedError,"unable to convert masscan record: #{record.inspect}")
  end
end

.status_record_to_row(status) ⇒ 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.



98
99
100
# File 'lib/ronin/masscan/converters/csv.rb', line 98

def self.status_record_to_row(status)
  ['status', status.status, status.protocol, status.port, status.reason.join(','), status.ttl, status.ip, status.timestamp]
end