Module: Ronin::Nmap::Converter
- Defined in:
- lib/ronin/nmap/converter.rb
Overview
Handles converting nmap XML 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(xml, output = nil, format:) ⇒ String
Converts parsed nmap XML into the desired format.
-
.convert_file(src, dest, format: infer_format_for(dest)) ⇒ Object
Converts an nmap XML 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(xml, output = nil, format:) ⇒ String
Converts parsed nmap XML into the desired format.
83 84 85 86 87 88 89 90 91 |
# File 'lib/ronin/nmap/converter.rb', line 83 def self.convert(xml,output=nil, format: ) if output Converters[format].convert(xml,output) else output = StringIO.new convert(xml,output, format: format) output.string end end |
.convert_file(src, dest, format: infer_format_for(dest)) ⇒ Object
Converts an nmap XML scan file into another format.
57 58 59 60 61 62 63 64 |
# File 'lib/ronin/nmap/converter.rb', line 57 def self.convert_file(src,dest, format: infer_format_for(dest)) xml = ::Nmap::XML.open(src) converter = Converters[format] File.open(dest,'w') do |output| converter.convert(xml,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.
107 108 109 110 111 |
# File 'lib/ronin/nmap/converter.rb', line 107 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 |