ruby-nmap 0.10.0 → 1.0.1

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.
Files changed (103) hide show
  1. checksums.yaml +4 -4
  2. data/.document +1 -0
  3. data/.editorconfig +11 -0
  4. data/.github/workflows/ruby.yml +31 -0
  5. data/ChangeLog.md +122 -71
  6. data/Gemfile +11 -5
  7. data/LICENSE.txt +1 -1
  8. data/README.md +88 -50
  9. data/Rakefile +5 -0
  10. data/UPGRADING.md +47 -0
  11. data/gemspec.yml +12 -5
  12. data/lib/nmap/command.rb +765 -0
  13. data/lib/nmap/version.rb +1 -1
  14. data/lib/nmap/xml/address.rb +38 -0
  15. data/lib/nmap/xml/cpe/url.rb +80 -0
  16. data/lib/nmap/xml/cpe.rb +47 -0
  17. data/lib/nmap/xml/hop.rb +22 -0
  18. data/lib/nmap/xml/host.rb +546 -0
  19. data/lib/nmap/xml/host_script.rb +26 -0
  20. data/lib/nmap/xml/hostname.rb +44 -0
  21. data/lib/nmap/xml/ip_id_sequence.rb +26 -0
  22. data/lib/nmap/xml/os.rb +131 -0
  23. data/lib/nmap/xml/os_class.rb +86 -0
  24. data/lib/nmap/xml/os_match.rb +22 -0
  25. data/lib/nmap/xml/port.rb +114 -0
  26. data/lib/nmap/xml/postscript.rb +26 -0
  27. data/lib/nmap/xml/prescript.rb +26 -0
  28. data/lib/nmap/xml/run_stat.rb +22 -0
  29. data/lib/nmap/xml/scan.rb +38 -0
  30. data/lib/nmap/xml/scan_task.rb +55 -0
  31. data/lib/nmap/xml/scanner.rb +22 -0
  32. data/lib/nmap/xml/script.rb +110 -0
  33. data/lib/nmap/xml/scripts.rb +33 -0
  34. data/lib/nmap/xml/sequence.rb +52 -0
  35. data/lib/nmap/xml/service.rb +172 -0
  36. data/lib/nmap/xml/status.rb +22 -0
  37. data/lib/nmap/xml/tcp_sequence.rb +48 -0
  38. data/lib/nmap/xml/tcp_ts_sequence.rb +26 -0
  39. data/lib/nmap/xml/traceroute.rb +73 -0
  40. data/lib/nmap/xml/uptime.rb +22 -0
  41. data/lib/nmap/xml.rb +31 -44
  42. data/spec/command_spec.rb +726 -0
  43. data/spec/fixtures/down_host_scan.xml +16 -0
  44. data/spec/{address_spec.rb → xml/address_spec.rb} +2 -2
  45. data/spec/{cpe → xml/cpe}/url_spec.rb +1 -1
  46. data/spec/{cpe_examples.rb → xml/cpe_examples.rb} +1 -1
  47. data/spec/{hop_spec.rb → xml/hop_spec.rb} +2 -2
  48. data/spec/{host_script_spec.rb → xml/host_script_spec.rb} +2 -2
  49. data/spec/{host_spec.rb → xml/host_spec.rb} +8 -8
  50. data/spec/{hostname_spec.rb → xml/hostname_spec.rb} +2 -2
  51. data/spec/{ip_id_sequence_spec.rb → xml/ip_id_sequence_spec.rb} +3 -3
  52. data/spec/{os_class_spec.rb → xml/os_class_spec.rb} +3 -3
  53. data/spec/{os_match_spec.rb → xml/os_match_spec.rb} +2 -2
  54. data/spec/{os_spec.rb → xml/os_spec.rb} +3 -3
  55. data/spec/{port_spec.rb → xml/port_spec.rb} +4 -5
  56. data/spec/{postscript_spec.rb → xml/postscript_spec.rb} +2 -2
  57. data/spec/{prescript_spec.rb → xml/prescript_spec.rb} +2 -2
  58. data/spec/{run_stat_spec.rb → xml/run_stat_spec.rb} +2 -2
  59. data/spec/{scan_spec.rb → xml/scan_spec.rb} +2 -2
  60. data/spec/{scan_task_spec.rb → xml/scan_task_spec.rb} +6 -6
  61. data/spec/{scanner_spec.rb → xml/scanner_spec.rb} +3 -3
  62. data/spec/xml/script_spec.rb +137 -0
  63. data/spec/xml/scripts_examples.rb +19 -0
  64. data/spec/{sequence_examples.rb → xml/sequence_examples.rb} +1 -0
  65. data/spec/{service_spec.rb → xml/service_spec.rb} +31 -5
  66. data/spec/{status_spec.rb → xml/status_spec.rb} +2 -2
  67. data/spec/{tcp_sequence_spec.rb → xml/tcp_sequence_spec.rb} +3 -3
  68. data/spec/{tcp_ts_sequence_spec.rb → xml/tcp_ts_sequence_spec.rb} +3 -3
  69. data/spec/{traceroute_spec.rb → xml/traceroute_spec.rb} +3 -3
  70. data/spec/{uptime_spec.rb → xml/uptime_spec.rb} +2 -2
  71. data/spec/xml_spec.rb +73 -44
  72. metadata +72 -66
  73. data/.travis.yml +0 -16
  74. data/lib/nmap/address.rb +0 -34
  75. data/lib/nmap/cpe/url.rb +0 -78
  76. data/lib/nmap/cpe.rb +0 -45
  77. data/lib/nmap/hop.rb +0 -20
  78. data/lib/nmap/host.rb +0 -587
  79. data/lib/nmap/host_script.rb +0 -18
  80. data/lib/nmap/hostname.rb +0 -42
  81. data/lib/nmap/ip_id_sequence.rb +0 -24
  82. data/lib/nmap/os.rb +0 -127
  83. data/lib/nmap/os_class.rb +0 -82
  84. data/lib/nmap/os_match.rb +0 -18
  85. data/lib/nmap/port.rb +0 -110
  86. data/lib/nmap/postscript.rb +0 -16
  87. data/lib/nmap/prescript.rb +0 -16
  88. data/lib/nmap/program.rb +0 -102
  89. data/lib/nmap/run_stat.rb +0 -20
  90. data/lib/nmap/scan.rb +0 -34
  91. data/lib/nmap/scan_task.rb +0 -53
  92. data/lib/nmap/scanner.rb +0 -18
  93. data/lib/nmap/scripts.rb +0 -71
  94. data/lib/nmap/sequence.rb +0 -50
  95. data/lib/nmap/service.rb +0 -170
  96. data/lib/nmap/status.rb +0 -18
  97. data/lib/nmap/task.rb +0 -387
  98. data/lib/nmap/tcp_sequence.rb +0 -46
  99. data/lib/nmap/tcp_ts_sequence.rb +0 -22
  100. data/lib/nmap/traceroute.rb +0 -71
  101. data/lib/nmap/uptime.rb +0 -20
  102. data/spec/scripts_examples.rb +0 -35
  103. data/spec/task_spec.rb +0 -150
data/spec/xml_spec.rb CHANGED
@@ -1,37 +1,20 @@
1
1
  require 'spec_helper'
2
2
  require 'nmap/xml'
3
3
 
4
- describe XML do
4
+ describe Nmap::XML do
5
5
  let(:file) { 'spec/fixtures/scan.xml' }
6
6
  let(:path) { File.expand_path(file) }
7
+ let(:doc) { Nokogiri::XML(File.open(path)) }
7
8
 
8
- subject { described_class.new(path) }
9
+ subject { described_class.new(doc) }
9
10
 
10
11
  describe "#initialize" do
11
- context "when given a Nokogiri::XML::Document" do
12
- let(:document) { Nokogiri::XML(File.read(path)) }
13
-
14
- it "should use the document" do
15
- expect(described_class.new(document).version).to eq(subject.version)
16
- end
17
- end
18
-
19
- context "when given an IO object" do
20
- let(:io) { File.new(path) }
21
-
22
- it "should parse the IO object" do
23
- expect(described_class.new(io).version).to eq(subject.version)
24
- end
25
- end
26
-
27
- context "when given a String" do
28
- it "should parse the file at the path" do
29
- expect(described_class.new(path).version).to eq(subject.version)
30
- end
12
+ it "must set #doc" do
13
+ expect(described_class.new(doc).doc).to be(doc)
31
14
  end
32
15
  end
33
16
 
34
- describe "parse" do
17
+ describe ".parse" do
35
18
  let(:xml) { File.read(path) }
36
19
 
37
20
  subject { described_class.parse(xml) }
@@ -45,7 +28,7 @@ describe XML do
45
28
  end
46
29
  end
47
30
 
48
- describe "open" do
31
+ describe ".open" do
49
32
  subject { described_class.open(path) }
50
33
 
51
34
  it "should return an XML object" do
@@ -109,7 +92,7 @@ describe XML do
109
92
  subject { super().each_run_stat.first }
110
93
 
111
94
  it "should yield RunStat objects" do
112
- expect(subject).to be_kind_of(RunStat)
95
+ expect(subject).to be_kind_of(Nmap::XML::RunStat)
113
96
  end
114
97
 
115
98
  it "should parse the end time" do
@@ -133,7 +116,7 @@ describe XML do
133
116
  subject { super().run_stats }
134
117
 
135
118
  it { is_expected.not_to be_empty }
136
- it { is_expected.to all(be_kind_of(RunStat)) }
119
+ it { is_expected.to all(be_kind_of(Nmap::XML::RunStat)) }
137
120
  end
138
121
 
139
122
  describe "#each_task" do
@@ -153,7 +136,7 @@ describe XML do
153
136
  end
154
137
 
155
138
  it "should parse the extrainfo" do
156
- expect(subject.extrainfo).not_to be_empty
139
+ expect(subject.extra_info).not_to be_empty
157
140
  end
158
141
  end
159
142
 
@@ -161,7 +144,7 @@ describe XML do
161
144
  subject { super().tasks }
162
145
 
163
146
  it { is_expected.not_to be_empty }
164
- it { is_expected.to all(be_kind_of(ScanTask)) }
147
+ it { is_expected.to all(be_kind_of(Nmap::XML::ScanTask)) }
165
148
  end
166
149
 
167
150
  describe "#task" do
@@ -170,7 +153,7 @@ describe XML do
170
153
  name = "Parallel DNS resolution of 1 host."
171
154
  task = subject.task(name)
172
155
 
173
- expect(task).to be_kind_of(ScanTask)
156
+ expect(task).to be_kind_of(Nmap::XML::ScanTask)
174
157
  expect(task.name).to be == name
175
158
  end
176
159
  end
@@ -198,7 +181,7 @@ describe XML do
198
181
  subject { super().each_host.first }
199
182
 
200
183
  it "should yield Host objects" do
201
- expect(subject).to be_kind_of(Host)
184
+ expect(subject).to be_kind_of(Nmap::XML::Host)
202
185
  end
203
186
  end
204
187
 
@@ -206,20 +189,62 @@ describe XML do
206
189
  subject { super().hosts }
207
190
 
208
191
  it { is_expected.not_to be_empty }
209
- it { expect(subject).to all(be_kind_of(Host)) }
192
+ it { expect(subject).to all(be_kind_of(Nmap::XML::Host)) }
210
193
  end
211
194
 
212
195
  describe "#host" do
213
196
  subject { super().host }
214
197
 
215
- it { expect(subject).to be_kind_of(Host) }
198
+ it { expect(subject).to be_kind_of(Nmap::XML::Host) }
199
+ end
200
+
201
+ describe "#each_down_host" do
202
+ let(:file) { 'spec/fixtures/down_host_scan.xml' }
203
+
204
+ context "when given a block" do
205
+ it "must yield Host objects" do
206
+ expect { |b|
207
+ subject.each_down_host(&b)
208
+ }.to yield_successive_args(Nmap::XML::Host)
209
+ end
210
+
211
+ it "status must be down" do
212
+ yielded_hosts = []
213
+
214
+ subject.each_down_host do |host|
215
+ yielded_hosts << host
216
+ end
217
+
218
+ expect(yielded_hosts).to_not be_empty
219
+ expect(yielded_hosts.map { |host| host.status.state }).to all(eq(:down))
220
+ end
221
+ end
222
+
223
+ context "when not given a block" do
224
+ it "must return an Enumerator for the method" do
225
+ expect(subject.each_down_host).to be_kind_of(Enumerator)
226
+ end
227
+ end
228
+ end
229
+
230
+ describe "#down_hosts" do
231
+ let(:file) { 'spec/fixtures/down_host_scan.xml' }
232
+
233
+ subject { super().down_hosts }
234
+
235
+ it { expect(subject).to_not be_empty }
236
+ it { expect(subject).to all(be_kind_of(Nmap::XML::Host)) }
237
+
238
+ it "should contain only up hosts" do
239
+ expect(subject.map { |host| host.status.state }).to all(eq(:down))
240
+ end
216
241
  end
217
242
 
218
243
  describe "#down_host" do
219
244
  pending "need down hosts in scan.xml" do
220
245
  subject { super().down_host }
221
246
 
222
- it { is_expected.to be_kind_of(Host) }
247
+ it { is_expected.to be_kind_of(Nmap::XML::Host) }
223
248
 
224
249
  it "should contain only up hosts" do
225
250
  expect(subject.status.state).to be(:down)
@@ -231,7 +256,7 @@ describe XML do
231
256
  subject { super().each_up_host.first }
232
257
 
233
258
  it "should yield Host objects" do
234
- expect(subject).to be_kind_of(Host)
259
+ expect(subject).to be_kind_of(Nmap::XML::Host)
235
260
  end
236
261
 
237
262
  it "should be up" do
@@ -242,18 +267,18 @@ describe XML do
242
267
  describe "#up_hosts" do
243
268
  subject { super().up_hosts }
244
269
 
245
- it { is_expected.not_to be_empty }
246
- it { is_expected.to all(be_kind_of(Host)) }
270
+ it { expect(subject).not_to be_empty }
271
+ it { expect(subject).to all(be_kind_of(Nmap::XML::Host)) }
247
272
 
248
273
  it "should contain only up hosts" do
249
- expect(subject.all? { |host| host.status.state == :up }).to be_truthy
274
+ expect(subject.map { |host| host.status.state }).to all(eq(:up))
250
275
  end
251
276
  end
252
277
 
253
278
  describe "#up_host" do
254
279
  subject { super().up_host }
255
280
 
256
- it { is_expected.to be_kind_of(Host) }
281
+ it { is_expected.to be_kind_of(Nmap::XML::Host) }
257
282
 
258
283
  it "should contain only up hosts" do
259
284
  expect(subject.status.state).to be(:up)
@@ -267,14 +292,18 @@ describe XML do
267
292
  end
268
293
 
269
294
  describe "#to_s" do
270
- it "should convert to a String" do
271
- expect(subject.to_s).to eq(path)
295
+ context "when #path is set" do
296
+ subject { described_class.new(doc, path: path) }
297
+
298
+ it "must return #path" do
299
+ expect(subject.to_s).to eq(path)
300
+ end
272
301
  end
273
- end
274
302
 
275
- describe "#inspect" do
276
- it "should include the class and path" do
277
- expect(subject.inspect).to eq("#<#{described_class}: #{path}>")
303
+ context "when #path is not set" do
304
+ it "must return the raw XML" do
305
+ expect(subject.to_s).to eq(doc.to_s)
306
+ end
278
307
  end
279
308
  end
280
309
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-nmap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Postmodern
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-18 00:00:00.000000000 Z
11
+ date: 2022-12-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -25,7 +25,7 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.3'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rprogram
28
+ name: command_mapper
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
@@ -52,7 +52,8 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '2.0'
55
- description: A Ruby interface to Nmap, the exploration tool and security / port scanner.
55
+ description: A Ruby API to nmap, the exploration tool and security / port scanner.
56
+ Allows automating nmap and parsing nmap XML files.
56
57
  email: postmodern.mod3@gmail.com
57
58
  executables: []
58
59
  extensions: []
@@ -60,87 +61,92 @@ extra_rdoc_files:
60
61
  - ChangeLog.md
61
62
  - LICENSE.txt
62
63
  - README.md
64
+ - UPGRADING.md
63
65
  files:
64
66
  - ".document"
67
+ - ".editorconfig"
68
+ - ".github/workflows/ruby.yml"
65
69
  - ".gitignore"
66
70
  - ".rspec"
67
- - ".travis.yml"
68
71
  - ".yardopts"
69
72
  - ChangeLog.md
70
73
  - Gemfile
71
74
  - LICENSE.txt
72
75
  - README.md
73
76
  - Rakefile
77
+ - UPGRADING.md
74
78
  - gemspec.yml
75
79
  - lib/nmap.rb
76
- - lib/nmap/address.rb
77
- - lib/nmap/cpe.rb
78
- - lib/nmap/cpe/url.rb
79
- - lib/nmap/hop.rb
80
- - lib/nmap/host.rb
81
- - lib/nmap/host_script.rb
82
- - lib/nmap/hostname.rb
83
- - lib/nmap/ip_id_sequence.rb
84
- - lib/nmap/os.rb
85
- - lib/nmap/os_class.rb
86
- - lib/nmap/os_match.rb
87
- - lib/nmap/port.rb
88
- - lib/nmap/postscript.rb
89
- - lib/nmap/prescript.rb
90
- - lib/nmap/program.rb
91
- - lib/nmap/run_stat.rb
92
- - lib/nmap/scan.rb
93
- - lib/nmap/scan_task.rb
94
- - lib/nmap/scanner.rb
95
- - lib/nmap/scripts.rb
96
- - lib/nmap/sequence.rb
97
- - lib/nmap/service.rb
98
- - lib/nmap/status.rb
99
- - lib/nmap/task.rb
100
- - lib/nmap/tcp_sequence.rb
101
- - lib/nmap/tcp_ts_sequence.rb
102
- - lib/nmap/traceroute.rb
103
- - lib/nmap/uptime.rb
80
+ - lib/nmap/command.rb
104
81
  - lib/nmap/version.rb
105
82
  - lib/nmap/xml.rb
83
+ - lib/nmap/xml/address.rb
84
+ - lib/nmap/xml/cpe.rb
85
+ - lib/nmap/xml/cpe/url.rb
86
+ - lib/nmap/xml/hop.rb
87
+ - lib/nmap/xml/host.rb
88
+ - lib/nmap/xml/host_script.rb
89
+ - lib/nmap/xml/hostname.rb
90
+ - lib/nmap/xml/ip_id_sequence.rb
91
+ - lib/nmap/xml/os.rb
92
+ - lib/nmap/xml/os_class.rb
93
+ - lib/nmap/xml/os_match.rb
94
+ - lib/nmap/xml/port.rb
95
+ - lib/nmap/xml/postscript.rb
96
+ - lib/nmap/xml/prescript.rb
97
+ - lib/nmap/xml/run_stat.rb
98
+ - lib/nmap/xml/scan.rb
99
+ - lib/nmap/xml/scan_task.rb
100
+ - lib/nmap/xml/scanner.rb
101
+ - lib/nmap/xml/script.rb
102
+ - lib/nmap/xml/scripts.rb
103
+ - lib/nmap/xml/sequence.rb
104
+ - lib/nmap/xml/service.rb
105
+ - lib/nmap/xml/status.rb
106
+ - lib/nmap/xml/tcp_sequence.rb
107
+ - lib/nmap/xml/tcp_ts_sequence.rb
108
+ - lib/nmap/xml/traceroute.rb
109
+ - lib/nmap/xml/uptime.rb
106
110
  - ruby-nmap.gemspec
107
- - spec/address_spec.rb
108
- - spec/cpe/url_spec.rb
109
- - spec/cpe_examples.rb
111
+ - spec/command_spec.rb
112
+ - spec/fixtures/down_host_scan.xml
110
113
  - spec/fixtures/local_scan.xml
111
114
  - spec/fixtures/scan.xml
112
- - spec/hop_spec.rb
113
- - spec/host_script_spec.rb
114
- - spec/host_spec.rb
115
- - spec/hostname_spec.rb
116
- - spec/ip_id_sequence_spec.rb
117
115
  - spec/nmap_spec.rb
118
- - spec/os_class_spec.rb
119
- - spec/os_match_spec.rb
120
- - spec/os_spec.rb
121
- - spec/port_spec.rb
122
- - spec/postscript_spec.rb
123
- - spec/prescript_spec.rb
124
- - spec/run_stat_spec.rb
125
- - spec/scan_spec.rb
126
- - spec/scan_task_spec.rb
127
- - spec/scanner_spec.rb
128
- - spec/scripts_examples.rb
129
- - spec/sequence_examples.rb
130
- - spec/service_spec.rb
131
116
  - spec/spec_helper.rb
132
- - spec/status_spec.rb
133
- - spec/task_spec.rb
134
- - spec/tcp_sequence_spec.rb
135
- - spec/tcp_ts_sequence_spec.rb
136
- - spec/traceroute_spec.rb
137
- - spec/uptime_spec.rb
117
+ - spec/xml/address_spec.rb
118
+ - spec/xml/cpe/url_spec.rb
119
+ - spec/xml/cpe_examples.rb
120
+ - spec/xml/hop_spec.rb
121
+ - spec/xml/host_script_spec.rb
122
+ - spec/xml/host_spec.rb
123
+ - spec/xml/hostname_spec.rb
124
+ - spec/xml/ip_id_sequence_spec.rb
125
+ - spec/xml/os_class_spec.rb
126
+ - spec/xml/os_match_spec.rb
127
+ - spec/xml/os_spec.rb
128
+ - spec/xml/port_spec.rb
129
+ - spec/xml/postscript_spec.rb
130
+ - spec/xml/prescript_spec.rb
131
+ - spec/xml/run_stat_spec.rb
132
+ - spec/xml/scan_spec.rb
133
+ - spec/xml/scan_task_spec.rb
134
+ - spec/xml/scanner_spec.rb
135
+ - spec/xml/script_spec.rb
136
+ - spec/xml/scripts_examples.rb
137
+ - spec/xml/sequence_examples.rb
138
+ - spec/xml/service_spec.rb
139
+ - spec/xml/status_spec.rb
140
+ - spec/xml/tcp_sequence_spec.rb
141
+ - spec/xml/tcp_ts_sequence_spec.rb
142
+ - spec/xml/traceroute_spec.rb
143
+ - spec/xml/uptime_spec.rb
138
144
  - spec/xml_spec.rb
139
- homepage: https://github.com/sophsec/ruby-nmap#readme
145
+ homepage: https://github.com/postmodern/ruby-nmap#readme
140
146
  licenses:
141
147
  - MIT
142
148
  metadata: {}
143
- post_install_message:
149
+ post_install_message:
144
150
  rdoc_options: []
145
151
  require_paths:
146
152
  - lib
@@ -156,8 +162,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
156
162
  version: '0'
157
163
  requirements:
158
164
  - nmap >= 5.00
159
- rubygems_version: 3.0.3
160
- signing_key:
165
+ rubygems_version: 3.3.26
166
+ signing_key:
161
167
  specification_version: 4
162
- summary: A Ruby interface to Nmap.
168
+ summary: A Ruby API to nmap.
163
169
  test_files: []
data/.travis.yml DELETED
@@ -1,16 +0,0 @@
1
- language: ruby
2
- before_install:
3
- - sudo apt-get install libxml2-dev libxslt1-dev
4
- - gem update --system
5
- - gem install bundler -v "~> 2.0"
6
- rvm:
7
- - 2.5
8
- - 2.6
9
- - 2.7
10
- - jruby
11
- - rbx
12
- matrix:
13
- allow_failures:
14
- - rvm: jruby
15
- - rvm: rbx
16
- script: rake test
data/lib/nmap/address.rb DELETED
@@ -1,34 +0,0 @@
1
- module Nmap
2
- #
3
- # Represents an IP or MAC address and Vendor name.
4
- #
5
- class Address < Struct.new(:type, :addr, :vendor)
6
-
7
- #
8
- # Initializes the address.
9
- #
10
- # @param [Symbol] type
11
- # The type of address.
12
- #
13
- # @param [String] addr
14
- # The address.
15
- #
16
- # @param [String, nil] vendor
17
- # The optional vendor.
18
- #
19
- def initialize(type,addr,vendor=nil)
20
- super(type,addr,vendor)
21
- end
22
-
23
- #
24
- # Converts the address to a String.
25
- #
26
- # @return [String]
27
- # The address.
28
- #
29
- def to_s
30
- self.addr.to_s
31
- end
32
-
33
- end
34
- end
data/lib/nmap/cpe/url.rb DELETED
@@ -1,78 +0,0 @@
1
- module Nmap
2
- module CPE
3
- #
4
- # Represets a [Common Platform Enumeration (CPE)][CPE] URL.
5
- #
6
- # [CPE]: http://nmap.org/book/output-formats-cpe.html
7
- #
8
- # @since 0.7.0
9
- #
10
- class URL < Struct.new(:part,:vendor,:product,:version,:update,:edition,
11
- :language)
12
-
13
- # CPE part codes
14
- PARTS = {
15
- '/a' => :application,
16
- '/h' => :hardware,
17
- '/o' => :os
18
- }
19
-
20
- #
21
- # Parses a CPE URL.
22
- #
23
- # @param [String] url
24
- # The raw URL.
25
- #
26
- # @return [URL]
27
- # The parsed URL.
28
- #
29
- def self.parse(url)
30
- scheme,
31
- part,
32
- vendor,
33
- product,
34
- version,
35
- update,
36
- edition,
37
- language = url.split(':',8)
38
-
39
- unless scheme == 'cpe'
40
- raise(ArgumentError,"CPE URLs must begin with 'cpe:'")
41
- end
42
-
43
- vendor = vendor.to_sym
44
- product = product.to_sym
45
- language = language.to_sym if language
46
-
47
- return new(
48
- PARTS[part],
49
- vendor,
50
- product,
51
- version,
52
- update,
53
- edition,
54
- language
55
- )
56
- end
57
-
58
- #
59
- # Converts the CPE URL back into a String.
60
- #
61
- # @return [String]
62
- # The raw CPE URL.
63
- #
64
- def to_s
65
- 'cpe:' + [
66
- PARTS.invert[part],
67
- vendor,
68
- product,
69
- version,
70
- update,
71
- edition,
72
- language
73
- ].compact.join(':')
74
- end
75
-
76
- end
77
- end
78
- end
data/lib/nmap/cpe.rb DELETED
@@ -1,45 +0,0 @@
1
- require 'nmap/cpe/url'
2
-
3
- module Nmap
4
- #
5
- # Mixins that adds methods for parsing [Common Platform Enumeration
6
- # (CPE)][CPE] information.
7
- #
8
- # [CPE]: http://nmap.org/book/output-formats-cpe.html
9
- #
10
- # @since 0.7.0
11
- #
12
- module CPE
13
- #
14
- # Parses each Common Platform Enumeration (CPE) String.
15
- #
16
- # @yield [cpe]
17
- # Passes each CPE URL to the given block.
18
- #
19
- # @yieldparam [URL] cpe
20
- # The CPE URL.
21
- #
22
- # @return [Enumerator]
23
- # If no block is given, an enumerator object will be returned.
24
- #
25
- def each_cpe
26
- return enum_for(__method__) unless block_given?
27
-
28
- @node.xpath('cpe').each do |cpe|
29
- yield URL.parse(cpe.inner_text)
30
- end
31
-
32
- return self
33
- end
34
-
35
- #
36
- # Parses each Common Platform Enumeration (CPE) String.
37
- #
38
- # @return [Array<URL>]
39
- # The CPE URLs.
40
- #
41
- def cpe
42
- each_cpe.to_a
43
- end
44
- end
45
- end
data/lib/nmap/hop.rb DELETED
@@ -1,20 +0,0 @@
1
- module Nmap
2
- #
3
- # Represents a hop in a traceroute.
4
- #
5
- # @since 0.7.0
6
- #
7
- class Hop < Struct.new(:addr, :host, :ttl, :rtt)
8
-
9
- #
10
- # Converts the hop to a String.
11
- #
12
- # @return [String]
13
- # The IP address of the hop.
14
- #
15
- def to_s
16
- self.addr.to_s
17
- end
18
-
19
- end
20
- end