Skip to content

Commit

Permalink
Added Ronin::Nmap.parse.
Browse files Browse the repository at this point in the history
  • Loading branch information
postmodern committed Jun 8, 2024
1 parent f87c950 commit f80e842
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
17 changes: 17 additions & 0 deletions lib/ronin/nmap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 13 additions & 0 deletions spec/nmap_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.*' }

Expand Down Expand Up @@ -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

0 comments on commit f80e842

Please sign in to comment.