Class: Ronin::Nmap::CLI::Commands::Convert Private

Inherits:
Ronin::Nmap::CLI::Command show all
Defined in:
lib/ronin/nmap/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 nmap XML file to JSON or CSV.

Usage

ronin-nmap convert [--format json|csv] XML_FILE [OUTPUT_FILE]

Option

-F, --format json|csv            The desired output format
-h, --help                       Print help information

Arguments

XML_FILE                         The input XML file to parse
OUTPUT_FILE                      The output file

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#format:json, ... (readonly)

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.

The desired output format.

Returns:

  • (:json, :csv, nil)


69
70
71
# File 'lib/ronin/nmap/cli/commands/convert.rb', line 69

def format
  @format
end

Instance Method Details

#run(xml_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-nmap convert command.

Parameters:

  • xml_file (String)

    The XML input file to parse.

  • output_file (String) (defaults to: nil)

    The output file to write to.



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/ronin/nmap/cli/commands/convert.rb', line 80

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

  if output_file
    if (format = options[:format])
      Converter.convert_file(xml_file,output_file, format: format)
    else
      Converter.convert_file(xml_file,output_file)
    end
  else
    unless (format = options[:format])
      print_error "must specify a --format if no output file is given"
      exit(-1)
    end

    xml = ::Nmap::XML.open(xml_file)

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