ruby-nmap 0.7.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8192a4dc58b09117d2aa6eb71a8a43440872f780
4
- data.tar.gz: 605bb8d11e670acc42b90abdfd01bfeebd8cab1c
3
+ metadata.gz: 388a408deac159e18f406b2a17c657ba3b775940
4
+ data.tar.gz: 0e532295c98b5e0b3e1e627b11d1891c3d25dac3
5
5
  SHA512:
6
- metadata.gz: 21b42a7d36d7aac99b722c38e80ff85646c1d677325ff6f480400a541ce8b9c9735dbbd58e227d13e321488458b30ae291783732955c70a784cd68481e6af7d9
7
- data.tar.gz: 15ecfb499d538467f5d70c8ce5276a79852c4e04a50fd4a117d4c419ca75b54a415e3f822a29623cb8c406926004d04a9a05f3198c07fb25c9dd2b2012d2d3a4
6
+ metadata.gz: 5c6f4a3931390deb37c27a64358055e04abd6e4f250f2c3379b9085f7885bf714006e43a2ca2bf73c44156f8057a41fc3f17d345663f7f49537f2462e0479c21
7
+ data.tar.gz: b3e882efab065007b1d7370106ac39f3472114cec80716e37017056f49288b008bed3f4f6cf7db05a8c31f0c0780ccf48aaa3f789f14326b48c271b8d2b00f26
@@ -1,3 +1,20 @@
1
+ ### 0.8.0 / 2014-04-16
2
+
3
+ * Added {Nmap::XML#each_down_host}.
4
+ * Added {Nmap::XML#down_hosts}.
5
+ * Added {Nmap::XML#host}.
6
+ * Added {Nmap::XML#up_host}.
7
+ * Added {Nmap::XML#down_host}.
8
+ * Added {Nmap::Host#hostname}.
9
+ * Added {Nmap::Hostname#user?}.
10
+ * Added {Nmap::Hostname#ptr?}.
11
+ * Added {Nmap::Program.sudo_scan}.
12
+ * Added {Nmap::Program#sudo_scan}.
13
+ * Renamed {Nmap::XML.load} to {Nmap::XML.parse}.
14
+ * Fixed a typo in the `--privileged` flag (@BrentonEarl)
15
+ * Allow multiple values in the `--script` flag.
16
+ * Alias {Nmap::Task#script_params} to `script_args`.
17
+
1
18
  ### 0.7.0 / 2014-05-09
2
19
 
3
20
  * Added {Nmap::CPE}.
data/Gemfile CHANGED
@@ -3,10 +3,12 @@ source 'https://rubygems.org'
3
3
  gemspec
4
4
 
5
5
  group :development do
6
- gem 'rake', '~> 10.0'
7
- gem 'rubygems-tasks', '~> 0.1'
8
- gem 'rspec', '~> 2.4'
6
+ gem 'rake'
7
+ gem 'rubygems-tasks', '~> 0.2'
8
+ gem 'rspec', '~> 3.0'
9
+
10
+ gem 'json'
9
11
  gem 'simplecov', '~> 0.7'
10
- gem 'kramdown', '~> 1.0'
11
- gem 'yard', '~> 0.7'
12
+ gem 'kramdown'
13
+ gem 'yard', '~> 0.8'
12
14
  end
@@ -1,6 +1,6 @@
1
1
  module Nmap
2
2
  #
3
- # Represents a IP or MAC address.
3
+ # Represents an IP or MAC address and Vendor name.
4
4
  #
5
5
  class Address < Struct.new(:type, :addr)
6
6
 
@@ -123,6 +123,20 @@ module Nmap
123
123
  end
124
124
  end
125
125
 
126
+ #
127
+ # Parses the MAC vendor of the host.
128
+ #
129
+ # @return [String]
130
+ # The Mac Vendor of the host.
131
+ #
132
+ # @since 0.8.0
133
+ #
134
+ def vendor
135
+ @vendor ||= if (vendor = @node.at("address[@vendor]"))
136
+ vendor['vendor']
137
+ end
138
+ end
139
+
126
140
  #
127
141
  # Parses the IPv4 address of the host.
128
142
  #
@@ -200,6 +214,17 @@ module Nmap
200
214
  each_hostname.to_a
201
215
  end
202
216
 
217
+ #
218
+ # The primary hostname of the host.
219
+ #
220
+ # @return [Hostname, nil]
221
+ #
222
+ # @since 0.8.0
223
+ #
224
+ def hostname
225
+ each_hostname.first
226
+ end
227
+
203
228
  #
204
229
  # Parses the OS guessing information of the host.
205
230
  #
@@ -525,12 +550,12 @@ module Nmap
525
550
  # Converts the host to a String.
526
551
  #
527
552
  # @return [String]
528
- # The address of the host.
553
+ # The hostname or address of the host.
529
554
  #
530
555
  # @see address
531
556
  #
532
557
  def to_s
533
- address.to_s
558
+ (hostname || address).to_s
534
559
  end
535
560
 
536
561
  #
@@ -6,6 +6,28 @@ module Nmap
6
6
  #
7
7
  class Hostname < Struct.new(:type, :name)
8
8
 
9
+ #
10
+ # Determines if the hostname was specified by the user.
11
+ #
12
+ # @return [Boolean]
13
+ #
14
+ # @since 0.8.0
15
+ #
16
+ def user?
17
+ self.type == 'user'
18
+ end
19
+
20
+ #
21
+ # Determines if the hostname is a DNS `PTR`.
22
+ #
23
+ # @return [Boolean]
24
+ #
25
+ # @since 0.8.0
26
+ #
27
+ def ptr?
28
+ self.type == 'PTR'
29
+ end
30
+
9
31
  #
10
32
  # Converts the hostname to a String.
11
33
  #
@@ -115,7 +115,7 @@ module Nmap
115
115
  #
116
116
  # Parses the OS match information.
117
117
  #
118
- # @see each_match
118
+ # @see #each_match
119
119
  #
120
120
  def each(&block)
121
121
  each_match(&block)
@@ -49,6 +49,18 @@ module Nmap
49
49
  find.scan(options,exec_options,&block)
50
50
  end
51
51
 
52
+ #
53
+ # Finds the `nmap` program and performs a scan, but runs `nmap` under
54
+ # `sudo`.
55
+ #
56
+ # @see scan
57
+ #
58
+ # @since 0.8.0
59
+ #
60
+ def self.sudo_scan(options={},exec_options={},&block)
61
+ find.sudo_scan(options,exec_options,&block)
62
+ end
63
+
52
64
  #
53
65
  # Performs a scan.
54
66
  #
@@ -75,5 +87,16 @@ module Nmap
75
87
  run_task(Task.new(options,&block),exec_options)
76
88
  end
77
89
 
90
+ #
91
+ # Performs a scan and runs `nmap` under `sudo`.
92
+ #
93
+ # @see #scan
94
+ #
95
+ # @since 0.8.0
96
+ #
97
+ def sudo_scan(options={},exec_options={},&block)
98
+ sudo_task(Task.new(options,&block),exec_options)
99
+ end
100
+
78
101
  end
79
102
  end
@@ -14,7 +14,7 @@ module Nmap
14
14
  # ### Host Discovery:
15
15
  #
16
16
  # * `-sL` - `nmap.list`
17
- # * `-sP` - `nmap.ping`
17
+ # * `-sn` - `nmap.ping`
18
18
  # * `-PN` - `nmap.skip_discovery`
19
19
  # * `-PS` - `nmap.syn_discovery`
20
20
  # * `-PA` - `nmap.ack_discovery`
@@ -156,8 +156,8 @@ module Nmap
156
156
  # * `--versiondb` - `nmap.versiondb`
157
157
  # * `--send-eth` - `nmap.raw_ethernet`
158
158
  # * `--send-ip` - `nmap.raw_ip`
159
- # * `--privledged` - `nmap.privledged`
160
- # * `--unprivledged` - `nmap.unprivledged`
159
+ # * `--privileged` - `nmap.privileged`
160
+ # * `--unprivileged` - `nmap.unprivileged`
161
161
  # * `--release-memory` - `nmap.release_memory`
162
162
  # * `--interactive` - `nmap.interactive`
163
163
  # * `-V` - `nmap.version`
@@ -177,7 +177,7 @@ module Nmap
177
177
 
178
178
  # HOST DISCOVERY:
179
179
  short_option :flag => '-sL', :name => :list
180
- short_option :flag => '-sP', :name => :ping
180
+ short_option :flag => '-sn', :name => :ping
181
181
  short_option :flag => '-PN', :name => :skip_discovery
182
182
  short_option :flag => '-PS', :name => :syn_discovery
183
183
  short_option :flag => '-PA', :name => :ack_discovery
@@ -241,10 +241,10 @@ module Nmap
241
241
 
242
242
  # SCRIPT SCAN:
243
243
  short_option :flag => '-sC', :name => :default_script
244
- long_option :flag => '--script'
245
- long_option :flag => '--script-args',
246
- :name => :script_params,
247
- :separator => ','
244
+ long_option :flag => '--script', :separator => ','
245
+ long_option :flag => '--script-args', :separator => ','
246
+ alias script_params script_args
247
+ alias script_params= script_args=
248
248
  long_option :flag => '--script-trace'
249
249
  long_option :flag => '--script-updatedb', :name => :update_scriptdb
250
250
 
@@ -323,7 +323,7 @@ module Nmap
323
323
  long_option :flag => '--versiondb'
324
324
  long_option :flag => '--send-eth', :name => :raw_ethernet
325
325
  long_option :flag => '--send-ip', :name => :raw_ip
326
- long_option :flag => '--privledged'
326
+ long_option :flag => '--privileged'
327
327
  long_option :flag => '--unprivleged'
328
328
  long_option :flag => '--release-memory'
329
329
  long_option :flag => '--interactive'
@@ -1,4 +1,4 @@
1
1
  module Nmap
2
2
  # ruby-nmap version
3
- VERSION = '0.7.0'
3
+ VERSION = '0.8.0'
4
4
  end
@@ -55,10 +55,19 @@ module Nmap
55
55
  # @yieldparam [XML] xml
56
56
  # The newly created XML object.
57
57
  #
58
+ # @since 0.8.0
59
+ #
60
+ def self.parse(text,&block)
61
+ new(Nokogiri::XML(text), &block)
62
+ end
63
+
64
+ #
65
+ # @deprecated Use {parse} instead.
66
+ #
58
67
  # @since 0.7.0
59
68
  #
60
69
  def self.load(text,&block)
61
- new(Nokogiri::XML(text), &block)
70
+ parse(text,&block)
62
71
  end
63
72
 
64
73
  #
@@ -263,6 +272,65 @@ module Nmap
263
272
  each_host.to_a
264
273
  end
265
274
 
275
+ #
276
+ # Returns the first host.
277
+ #
278
+ # @return [Host]
279
+ #
280
+ # @since 0.8.0
281
+ #
282
+ def host
283
+ each_host.first
284
+ end
285
+
286
+ #
287
+ # Parses the hosts that were found to be down during the scan.
288
+ #
289
+ # @yield [host]
290
+ # Each host will be passed to a given block.
291
+ #
292
+ # @yieldparam [Host] host
293
+ # A down host in the scan.
294
+ #
295
+ # @return [XML, Enumerator]
296
+ # The XML parser. If no block was given, an enumerator object will
297
+ # be returned.
298
+ #
299
+ # @since 0.8.0
300
+ #
301
+ def each_down_host
302
+ return enum_for(__method__) unless block_given?
303
+
304
+ @doc.xpath("/nmaprun/host[status[@state='down']]").each do |host|
305
+ yield Host.new(host)
306
+ end
307
+
308
+ return self
309
+ end
310
+
311
+ #
312
+ # Parses the hosts found to be down during the scan.
313
+ #
314
+ # @return [Array<Host>]
315
+ # The down hosts in the scan.
316
+ #
317
+ # @since 0.8.0
318
+ #
319
+ def down_hosts
320
+ each_down_host.to_a
321
+ end
322
+
323
+ #
324
+ # Returns the first host found to be down during the scan.
325
+ #
326
+ # @return [Host]
327
+ #
328
+ # @since 0.8.0
329
+ #
330
+ def down_host
331
+ each_down_host.first
332
+ end
333
+
266
334
  #
267
335
  # Parses the hosts that were found to be up during the scan.
268
336
  #
@@ -296,6 +364,17 @@ module Nmap
296
364
  each_up_host.to_a
297
365
  end
298
366
 
367
+ #
368
+ # Returns the first host found to be up during the scan.
369
+ #
370
+ # @return [Host]
371
+ #
372
+ # @since 0.8.0
373
+ #
374
+ def up_host
375
+ each_up_host.first
376
+ end
377
+
299
378
  #
300
379
  # Parses the hosts that were found to be up during the scan.
301
380
  #
@@ -66,7 +66,7 @@ Gem::Specification.new do |gemspec|
66
66
  gemspec.extra_rdoc_files = Array(metadata['extra_doc_files'])
67
67
 
68
68
  gemspec.post_install_message = metadata['post_install_message']
69
- gemspec.requirements = metadata['requirements']
69
+ gemspec.requirements = Array(metadata['requirements'])
70
70
 
71
71
  if gemspec.respond_to?(:required_ruby_version=)
72
72
  gemspec.required_ruby_version = metadata['required_ruby_version']
@@ -8,7 +8,7 @@ describe Address do
8
8
  subject { described_class.new(:ipv4, addr) }
9
9
 
10
10
  it "should return the address" do
11
- subject.to_s.should == addr
11
+ expect(subject.to_s).to eq(addr)
12
12
  end
13
13
  end
14
14
  end
@@ -4,9 +4,9 @@ describe CPE::URL do
4
4
  describe "parse" do
5
5
  context "when the URL does not start with 'cpe:'" do
6
6
  it "should raise an ArgumentError" do
7
- lambda {
7
+ expect {
8
8
  described_class.parse('foo:')
9
- }.should raise_error(ArgumentError)
9
+ }.to raise_error(ArgumentError)
10
10
  end
11
11
  end
12
12
 
@@ -20,13 +20,13 @@ describe CPE::URL do
20
20
  end
21
21
 
22
22
  it "should leave them nil" do
23
- subject.vendor.should == vendor
24
- subject.product.should == product
25
- subject.version.should == version
23
+ expect(subject.vendor).to eq(vendor)
24
+ expect(subject.product).to eq(product)
25
+ expect(subject.version).to eq(version)
26
26
 
27
- subject.update.should be_nil
28
- subject.edition.should be_nil
29
- subject.language.should be_nil
27
+ expect(subject.update).to be_nil
28
+ expect(subject.edition).to be_nil
29
+ expect(subject.language).to be_nil
30
30
  end
31
31
  end
32
32
 
@@ -34,7 +34,7 @@ describe CPE::URL do
34
34
  subject { described_class.parse("cpe:/h:foo:bar:baz") }
35
35
 
36
36
  it "should parse it as :hardware" do
37
- subject.part.should == :hardware
37
+ expect(subject.part).to eq(:hardware)
38
38
  end
39
39
  end
40
40
 
@@ -42,7 +42,7 @@ describe CPE::URL do
42
42
  subject { described_class.parse("cpe:/a:foo:bar:baz") }
43
43
 
44
44
  it "should parse it as :application" do
45
- subject.part.should == :application
45
+ expect(subject.part).to eq(:application)
46
46
  end
47
47
  end
48
48
 
@@ -50,7 +50,7 @@ describe CPE::URL do
50
50
  subject { described_class.parse("cpe:/o:foo:bar:baz") }
51
51
 
52
52
  it "should parse it as :os" do
53
- subject.part.should == :os
53
+ expect(subject.part).to eq(:os)
54
54
  end
55
55
  end
56
56
  end
@@ -61,14 +61,14 @@ describe CPE::URL do
61
61
  let(:version) { '2.6.39' }
62
62
 
63
63
  it "should add the scheme 'cpe:'" do
64
- subject.to_s.should start_with('cpe:')
64
+ expect(subject.to_s).to start_with('cpe:')
65
65
  end
66
66
 
67
67
  context "when fields are nil" do
68
68
  subject { described_class.new(:os,vendor,product,version) }
69
69
 
70
70
  it "should omit them" do
71
- subject.to_s.should == "cpe:/o:#{vendor}:#{product}:#{version}"
71
+ expect(subject.to_s).to eq("cpe:/o:#{vendor}:#{product}:#{version}")
72
72
  end
73
73
  end
74
74
 
@@ -76,7 +76,7 @@ describe CPE::URL do
76
76
  subject { described_class.new(:hardware) }
77
77
 
78
78
  it "should map it to /h" do
79
- subject.to_s.should == "cpe:/h"
79
+ expect(subject.to_s).to eq("cpe:/h")
80
80
  end
81
81
  end
82
82
 
@@ -84,7 +84,7 @@ describe CPE::URL do
84
84
  subject { described_class.new(:application) }
85
85
 
86
86
  it "should map it to /h" do
87
- subject.to_s.should == "cpe:/a"
87
+ expect(subject.to_s).to eq("cpe:/a")
88
88
  end
89
89
  end
90
90
 
@@ -92,7 +92,7 @@ describe CPE::URL do
92
92
  subject { described_class.new(:os) }
93
93
 
94
94
  it "should map it to /h" do
95
- subject.to_s.should == "cpe:/o"
95
+ expect(subject.to_s).to eq("cpe:/o")
96
96
  end
97
97
  end
98
98
  end