From f80e842e8a6130f126e17aa41bec33e8e386789f Mon Sep 17 00:00:00 2001 From: Postmodern Date: Fri, 7 Jun 2024 23:36:47 -0700 Subject: [PATCH] Added `Ronin::Nmap.parse`. --- lib/ronin/nmap.rb | 17 +++++++++++++++++ spec/nmap_spec.rb | 13 +++++++++++++ 2 files changed, 30 insertions(+) diff --git a/lib/ronin/nmap.rb b/lib/ronin/nmap.rb index 09daef7..be350c4 100644 --- a/lib/ronin/nmap.rb +++ b/lib/ronin/nmap.rb @@ -196,5 +196,22 @@ def self.scan(*targets, sudo: nil, **kwargs,&block) ::Nmap::XML.open(nmap.output_xml) end end + + # + # Parses a nmap XML file. + # + # @param [String] path + # The path to the nmap XML file. + # + # @return [::Nmap::XML] + # The parsed nmap XML file. + # + # @see https://rubydoc.info/gems/ruby-nmap/Nmap/XML + # + # @api public + # + def self.parse(path) + ::Nmap::XML.open(path) + end end end diff --git a/spec/nmap_spec.rb b/spec/nmap_spec.rb index d272f59..662cb22 100644 --- a/spec/nmap_spec.rb +++ b/spec/nmap_spec.rb @@ -2,6 +2,8 @@ require 'ronin/nmap' RSpec.describe Ronin::Nmap do + let(:fixtures_dir) { File.join(__dir__,'fixtures') } + describe '.scan' do let(:targets) { '192.168.1.*' } @@ -57,4 +59,15 @@ end end end + + describe ".parse" do + let(:path) { File.join(fixtures_dir,'nmap.xml') } + + it "must return a Nmap::XML object for the given path" do + xml = subject.parse(path) + + expect(xml).to be_kind_of(Nmap::XML) + expect(xml.path).to eq(path) + end + end end