ruby-nmap 0.9.3 → 1.0.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.
Files changed (107) hide show
  1. checksums.yaml +5 -5
  2. data/.document +1 -0
  3. data/.editorconfig +11 -0
  4. data/.github/workflows/ruby.yml +31 -0
  5. data/ChangeLog.md +122 -67
  6. data/Gemfile +11 -5
  7. data/LICENSE.txt +1 -1
  8. data/README.md +88 -50
  9. data/Rakefile +8 -3
  10. data/UPGRADING.md +47 -0
  11. data/gemspec.yml +6 -6
  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 +46 -44
  42. data/ruby-nmap.gemspec +38 -83
  43. data/spec/command_spec.rb +726 -0
  44. data/spec/fixtures/down_host_scan.xml +16 -0
  45. data/spec/{local_scan.xml → fixtures/local_scan.xml} +1 -1
  46. data/spec/{scan.xml → fixtures/scan.xml} +1 -1
  47. data/spec/spec_helper.rb +2 -2
  48. data/spec/{address_spec.rb → xml/address_spec.rb} +2 -2
  49. data/spec/{cpe → xml/cpe}/url_spec.rb +1 -1
  50. data/spec/{cpe_examples.rb → xml/cpe_examples.rb} +1 -1
  51. data/spec/{hop_spec.rb → xml/hop_spec.rb} +2 -2
  52. data/spec/{host_script_spec.rb → xml/host_script_spec.rb} +2 -2
  53. data/spec/{host_spec.rb → xml/host_spec.rb} +12 -8
  54. data/spec/{hostname_spec.rb → xml/hostname_spec.rb} +2 -2
  55. data/spec/{ip_id_sequence_spec.rb → xml/ip_id_sequence_spec.rb} +3 -3
  56. data/spec/{os_class_spec.rb → xml/os_class_spec.rb} +3 -3
  57. data/spec/{os_match_spec.rb → xml/os_match_spec.rb} +2 -2
  58. data/spec/{os_spec.rb → xml/os_spec.rb} +3 -3
  59. data/spec/{port_spec.rb → xml/port_spec.rb} +10 -5
  60. data/spec/{postscript_spec.rb → xml/postscript_spec.rb} +2 -2
  61. data/spec/{prescript_spec.rb → xml/prescript_spec.rb} +2 -2
  62. data/spec/{run_stat_spec.rb → xml/run_stat_spec.rb} +2 -2
  63. data/spec/{scan_spec.rb → xml/scan_spec.rb} +2 -2
  64. data/spec/{scan_task_spec.rb → xml/scan_task_spec.rb} +6 -6
  65. data/spec/{scanner_spec.rb → xml/scanner_spec.rb} +3 -3
  66. data/spec/xml/script_spec.rb +137 -0
  67. data/spec/xml/scripts_examples.rb +19 -0
  68. data/spec/{sequence_examples.rb → xml/sequence_examples.rb} +1 -0
  69. data/spec/{service_spec.rb → xml/service_spec.rb} +31 -5
  70. data/spec/{status_spec.rb → xml/status_spec.rb} +4 -3
  71. data/spec/{tcp_sequence_spec.rb → xml/tcp_sequence_spec.rb} +3 -3
  72. data/spec/{tcp_ts_sequence_spec.rb → xml/tcp_ts_sequence_spec.rb} +3 -3
  73. data/spec/{traceroute_spec.rb → xml/traceroute_spec.rb} +3 -3
  74. data/spec/{uptime_spec.rb → xml/uptime_spec.rb} +2 -2
  75. data/spec/xml_spec.rb +93 -45
  76. metadata +78 -99
  77. data/.travis.yml +0 -14
  78. data/lib/nmap/address.rb +0 -34
  79. data/lib/nmap/cpe/url.rb +0 -78
  80. data/lib/nmap/cpe.rb +0 -45
  81. data/lib/nmap/hop.rb +0 -20
  82. data/lib/nmap/host.rb +0 -586
  83. data/lib/nmap/host_script.rb +0 -18
  84. data/lib/nmap/hostname.rb +0 -42
  85. data/lib/nmap/ip_id_sequence.rb +0 -24
  86. data/lib/nmap/os.rb +0 -127
  87. data/lib/nmap/os_class.rb +0 -82
  88. data/lib/nmap/os_match.rb +0 -18
  89. data/lib/nmap/port.rb +0 -99
  90. data/lib/nmap/postscript.rb +0 -16
  91. data/lib/nmap/prescript.rb +0 -16
  92. data/lib/nmap/program.rb +0 -102
  93. data/lib/nmap/run_stat.rb +0 -20
  94. data/lib/nmap/scan.rb +0 -34
  95. data/lib/nmap/scan_task.rb +0 -50
  96. data/lib/nmap/scanner.rb +0 -18
  97. data/lib/nmap/scripts.rb +0 -71
  98. data/lib/nmap/sequence.rb +0 -50
  99. data/lib/nmap/service.rb +0 -170
  100. data/lib/nmap/status.rb +0 -18
  101. data/lib/nmap/task.rb +0 -381
  102. data/lib/nmap/tcp_sequence.rb +0 -46
  103. data/lib/nmap/tcp_ts_sequence.rb +0 -22
  104. data/lib/nmap/traceroute.rb +0 -71
  105. data/lib/nmap/uptime.rb +0 -20
  106. data/spec/scripts_examples.rb +0 -35
  107. data/spec/task_spec.rb +0 -150
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
data/lib/nmap/host.rb DELETED
@@ -1,586 +0,0 @@
1
- require 'nmap/status'
2
- require 'nmap/address'
3
- require 'nmap/hostname'
4
- require 'nmap/os'
5
- require 'nmap/port'
6
- require 'nmap/ip_id_sequence'
7
- require 'nmap/tcp_sequence'
8
- require 'nmap/tcp_ts_sequence'
9
- require 'nmap/uptime'
10
- require 'nmap/traceroute'
11
- require 'nmap/host_script'
12
-
13
- require 'nokogiri'
14
- require 'time'
15
-
16
- module Nmap
17
- #
18
- # Wraps a `host` XML element.
19
- #
20
- class Host
21
-
22
- include Enumerable
23
-
24
- #
25
- # Creates a new Host object.
26
- #
27
- # @param [Nokogiri::XML::Node] node
28
- # The XML node that contains the host information.
29
- #
30
- def initialize(node)
31
- @node = node
32
- end
33
-
34
- #
35
- # The time the host was first scanned.
36
- #
37
- # @return [Time]
38
- # The time the host was first scanned.
39
- #
40
- # @since 0.1.2
41
- #
42
- def start_time
43
- @start_time ||= Time.at(@node['starttime'].to_i)
44
- end
45
-
46
- #
47
- # The time the host was last scanned.
48
- #
49
- # @return [Time]
50
- # The time the host was last scanned.
51
- #
52
- # @since 0.1.2
53
- #
54
- def end_time
55
- @end_time ||= Time.at(@node['endtime'].to_i)
56
- end
57
-
58
- #
59
- # Parses the status of the host.
60
- #
61
- # @return [Status]
62
- # The status of the host.
63
- #
64
- def status
65
- unless @status
66
- status = @node.at_xpath('status')
67
-
68
- @status = Status.new(
69
- status['state'].to_sym,
70
- status['reason']
71
- )
72
- end
73
-
74
- return @status
75
- end
76
-
77
- #
78
- # Parses each address of the host.
79
- #
80
- # @yield [addr]
81
- # Each parsed address will be pass to a given block.
82
- #
83
- # @yieldparam [Address] addr
84
- # A address of the host.
85
- #
86
- # @return [Host, Enumerator]
87
- # The host.
88
- # If no block was given, an enumerator will be returned.
89
- #
90
- def each_address
91
- return enum_for(__method__) unless block_given?
92
-
93
- @node.xpath("address[@addr]").each do |addr|
94
- address = Address.new(
95
- addr['addrtype'].to_sym,
96
- addr['addr'],
97
- addr['vendor']
98
- )
99
-
100
- yield address
101
- end
102
-
103
- return self
104
- end
105
-
106
- #
107
- # Parses the addresses of the host.
108
- #
109
- # @return [Array<Host>]
110
- # The addresses of the host.
111
- #
112
- def addresses
113
- each_address.to_a
114
- end
115
-
116
- #
117
- # Parses the MAC address of the host.
118
- #
119
- # @return [String]
120
- # The MAC address of the host.
121
- #
122
- def mac
123
- @mac ||= if (addr = @node.at_xpath("address[@addrtype='mac']"))
124
- addr['addr']
125
- end
126
- end
127
-
128
- #
129
- # Parses the MAC vendor of the host.
130
- #
131
- # @return [String]
132
- # The Mac Vendor of the host.
133
- #
134
- # @since 0.8.0
135
- #
136
- def vendor
137
- @vendor ||= if (vendor = @node.at_xpath("address/@vendor"))
138
- vendor.inner_text
139
- end
140
- end
141
-
142
- #
143
- # Parses the IPv4 address of the host.
144
- #
145
- # @return [String]
146
- # The IPv4 address of the host.
147
- #
148
- def ipv4
149
- @ipv4 ||= if (addr = @node.at_xpath("address[@addrtype='ipv4']"))
150
- addr['addr']
151
- end
152
- end
153
-
154
- #
155
- # Parses the IPv6 address of the host.
156
- #
157
- # @return [String]
158
- # The IPv6 address of the host.
159
- #
160
- def ipv6
161
- @ipv6 ||= if (addr = @node.at_xpath("address[@addrtype='ipv6']"))
162
- addr['addr']
163
- end
164
- end
165
-
166
- #
167
- # The IP address of the host.
168
- #
169
- # @return [String]
170
- # The IPv4 or IPv6 address of the host.
171
- #
172
- def ip
173
- ipv6 || ipv4
174
- end
175
-
176
- #
177
- # The address of the host.
178
- #
179
- # @return [String]
180
- # The IP or MAC address of the host.
181
- #
182
- def address
183
- ip || mac
184
- end
185
-
186
- #
187
- # Parses the hostnames of the host.
188
- #
189
- # @yield [host]
190
- # Each parsed hostname will be passed to the given block.
191
- #
192
- # @yieldparam [Hostname] host
193
- # A hostname of the host.
194
- #
195
- # @return [Host, Enumerator]
196
- # The host.
197
- # If no block was given, an enumerator will be returned.
198
- #
199
- def each_hostname
200
- return enum_for(__method__) unless block_given?
201
-
202
- @node.xpath("hostnames/hostname[@name]").each do |host|
203
- yield Hostname.new(host['type'],host['name'])
204
- end
205
-
206
- return self
207
- end
208
-
209
- #
210
- # Parses the hostnames of the host.
211
- #
212
- # @return [Array<Hostname>]
213
- # The hostnames of the host.
214
- #
215
- def hostnames
216
- each_hostname.to_a
217
- end
218
-
219
- #
220
- # The primary hostname of the host.
221
- #
222
- # @return [Hostname, nil]
223
- #
224
- # @since 0.8.0
225
- #
226
- def hostname
227
- each_hostname.first
228
- end
229
-
230
- #
231
- # Parses the OS guessing information of the host.
232
- #
233
- # @yield [os]
234
- # If a block is given, it will be passed the OS guessing information.
235
- #
236
- # @yieldparam [OS] os
237
- # The OS guessing information.
238
- #
239
- # @return [OS]
240
- # The OS guessing information.
241
- #
242
- def os
243
- @os ||= if (os = @node.at_xpath('os'))
244
- OS.new(os)
245
- end
246
-
247
- yield @os if (@os && block_given?)
248
- return @os
249
- end
250
-
251
- #
252
- # Parses the Uptime analysis of the host.
253
- #
254
- # @yield [uptime]
255
- # If a block is given, it will be passed the resulting object
256
- #
257
- # @yieldparam [Uptime]
258
- # Uptime value.
259
- #
260
- # @return [Uptime]
261
- # The parsed object.
262
- #
263
- # @since 0.7.0
264
- #
265
- def uptime
266
- @uptime ||= if (uptime = @node.at_xpath('uptime'))
267
- Uptime.new(
268
- uptime['seconds'].to_i,
269
- Time.parse(uptime['lastboot'])
270
- )
271
- end
272
-
273
- yield @uptime if (@uptime && block_given?)
274
- return @uptime
275
- end
276
-
277
- #
278
- # Parses the Tcp Sequence number analysis of the host.
279
- #
280
- # @yield [sequence]
281
- # If a block is given, it will be passed the resulting object
282
- #
283
- # @yieldparam [TcpSequence] sequence
284
- # Tcp Sequence number analysis.
285
- #
286
- # @return [TcpSequence]
287
- # The parsed object.
288
- #
289
- def tcp_sequence
290
- @tcp_sequence ||= if (seq = @node.at_xpath('tcpsequence'))
291
- TcpSequence.new(seq)
292
- end
293
-
294
- yield @tcp_sequence if (@tcp_sequence && block_given?)
295
- return @tcp_sequence
296
- end
297
-
298
- #
299
- # @deprecated Use {#tcp_sequence} instead.
300
- #
301
- def tcpsequence(&block)
302
- warn "DEPRECATION: use #{self.class}#tcp_sequence instead"
303
-
304
- tcp_sequence(&block)
305
- end
306
-
307
- #
308
- # Parses the IPID sequence number analysis of the host.
309
- #
310
- # @yield [ipidsequence]
311
- # If a block is given, it will be passed the resulting object
312
- #
313
- # @yieldparam [IpIdSequence] ipidsequence
314
- # IPID Sequence number analysis.
315
- #
316
- # @return [IpIdSequence]
317
- # The parsed object.
318
- #
319
- def ip_id_sequence
320
- @ip_id_sequence ||= if (seq = @node.at_xpath('ipidsequence'))
321
- IpIdSequence.new(seq)
322
- end
323
-
324
- yield @ip_id_sequence if (@ip_id_sequence && block_given?)
325
- return @ip_id_sequence
326
- end
327
-
328
- #
329
- # @deprecated Use {#ip_id_sequence} instead.
330
- #
331
- def ipidsequence(&block)
332
- warn "DEPRECATION: use #{self.class}#ip_id_sequence instead"
333
-
334
- ip_id_sequence(&block)
335
- end
336
-
337
- #
338
- # Parses the TCP Timestamp sequence number analysis of the host.
339
- #
340
- # @yield [tcptssequence]
341
- # If a block is given, it will be passed the resulting object
342
- #
343
- # @yieldparam [TcpTsSequence] tcptssequence
344
- # TCP Timestamp Sequence number analysis.
345
- #
346
- # @return [TcpTsSequence]
347
- # The parsed object.
348
- #
349
- def tcp_ts_sequence
350
- @tcp_ts_sequence ||= if (seq = @node.at_xpath('tcptssequence'))
351
- TcpTsSequence.new(seq)
352
- end
353
-
354
- yield @tcp_ts_sequence if (@tcp_ts_sequence && block_given?)
355
- return @tcp_ts_sequence
356
- end
357
-
358
- #
359
- # @deprecated Use {#tcp_ts_sequence} instead.
360
- #
361
- def tcptssequence(&block)
362
- warn "DEPRECATION: use #{self.class}#tcp_ts_sequence instead"
363
-
364
- tcp_ts_sequence(&block)
365
- end
366
-
367
- #
368
- # Parses the scanned ports of the host.
369
- #
370
- # @yield [port]
371
- # Each scanned port of the host.
372
- #
373
- # @yieldparam [Port] port
374
- # A scanned port of the host.
375
- #
376
- # @return [Host, Enumerator]
377
- # The host.
378
- # If no block was given, an enumerator will be returned.
379
- #
380
- def each_port
381
- return enum_for(__method__) unless block_given?
382
-
383
- @node.xpath("ports/port").each do |port|
384
- yield Port.new(port)
385
- end
386
-
387
- return self
388
- end
389
-
390
- #
391
- # Parses the scanned ports of the host.
392
- #
393
- # @return [Array<Port>]
394
- # The scanned ports of the host.
395
- #
396
- def ports
397
- each_port.to_a
398
- end
399
-
400
- #
401
- # Parses the open ports of the host.
402
- #
403
- # @yield [port]
404
- # Each open port of the host.
405
- #
406
- # @yieldparam [Port] port
407
- # An open scanned port of the host.
408
- #
409
- # @return [Host, Enumerator]
410
- # The host.
411
- # If no block was given, an enumerator will be returned.
412
- #
413
- def each_open_port
414
- return enum_for(__method__) unless block_given?
415
-
416
- @node.xpath("ports/port[state/@state='open']").each do |port|
417
- yield Port.new(port)
418
- end
419
-
420
- return self
421
- end
422
-
423
- #
424
- # Parses the open ports of the host.
425
- #
426
- # @return [Array<Port>]
427
- # The open ports of the host.
428
- #
429
- def open_ports
430
- each_open_port.to_a
431
- end
432
-
433
- #
434
- # Parses the TCP ports of the host.
435
- #
436
- # @yield [port]
437
- # Each TCP port of the host.
438
- #
439
- # @yieldparam [Port] port
440
- # An TCP scanned port of the host.
441
- #
442
- # @return [Host, Enumerator]
443
- # The host.
444
- # If no block was given, an enumerator will be returned.
445
- #
446
- def each_tcp_port
447
- return enum_for(__method__) unless block_given?
448
-
449
- @node.xpath("ports/port[@protocol='tcp']").each do |port|
450
- yield Port.new(port)
451
- end
452
-
453
- return self
454
- end
455
-
456
- #
457
- # Parses the TCP ports of the host.
458
- #
459
- # @return [Array<Port>]
460
- # The TCP ports of the host.
461
- #
462
- def tcp_ports
463
- each_tcp_port.to_a
464
- end
465
-
466
- #
467
- # Parses the UDP ports of the host.
468
- #
469
- # @yield [port]
470
- # Each UDP port of the host.
471
- #
472
- # @yieldparam [Port] port
473
- # An UDP scanned port of the host.
474
- #
475
- # @return [Host, Enumerator]
476
- # The host.
477
- # If no block was given, an enumerator will be returned.
478
- #
479
- def each_udp_port
480
- return enum_for(__method__) unless block_given?
481
-
482
- @node.xpath("ports/port[@protocol='udp']").each do |port|
483
- yield Port.new(port)
484
- end
485
-
486
- return self
487
- end
488
-
489
- #
490
- # Parses the UDP ports of the host.
491
- #
492
- # @return [Array<Port>]
493
- # The UDP ports of the host.
494
- #
495
- def udp_ports
496
- each_udp_port.to_a
497
- end
498
-
499
- #
500
- # Parses the open ports of the host.
501
- #
502
- # @see each_open_port
503
- #
504
- def each(&block)
505
- each_open_port(&block)
506
- end
507
-
508
- #
509
- # The output from the NSE scripts ran against the host.
510
- #
511
- # @return [Hash{String => String}]
512
- # The NSE script names and output.
513
- #
514
- # @since 0.3.0
515
- #
516
- # @deprecated Use {#host_script} instead.
517
- #
518
- def scripts
519
- if host_script
520
- host_script.scripts
521
- else
522
- {}
523
- end
524
- end
525
-
526
- #
527
- # The NSE scripts ran against the host.
528
- #
529
- # @return [HostScript, nil]
530
- # Contains the host script output and data.
531
- #
532
- # @since 0.9.0
533
- #
534
- def host_script
535
- @host_script ||= if (hostscript = @node.at_xpath('hostscript'))
536
- HostScript.new(hostscript)
537
- end
538
- end
539
-
540
- #
541
- # Parses the traceroute information, if present.
542
- #
543
- # @yield [traceroute]
544
- # If a block is given, it will be passed the traceroute information.
545
- #
546
- # @yieldparam [Traceroute] traceroute
547
- # The traceroute information.
548
- #
549
- # @return [Traceroute]
550
- # The traceroute information.
551
- #
552
- # @since 0.7.0
553
- #
554
- def traceroute
555
- @traceroute ||= if (trace = @node.at_xpath('trace'))
556
- Traceroute.new(trace)
557
- end
558
-
559
- yield @traceroute if (@traceroute && block_given?)
560
- return @traceroute
561
- end
562
-
563
- #
564
- # Converts the host to a String.
565
- #
566
- # @return [String]
567
- # The hostname or address of the host.
568
- #
569
- # @see address
570
- #
571
- def to_s
572
- (hostname || address).to_s
573
- end
574
-
575
- #
576
- # Inspects the host.
577
- #
578
- # @return [String]
579
- # The inspected host.
580
- #
581
- def inspect
582
- "#<#{self.class}: #{self}>"
583
- end
584
-
585
- end
586
- end
@@ -1,18 +0,0 @@
1
- require 'nmap/scripts'
2
-
3
- module Nmap
4
- #
5
- # Represents the `hostscript` element.
6
- #
7
- # @since 0.9.0
8
- #
9
- class HostScript
10
-
11
- include Scripts
12
-
13
- def initialize(node)
14
- @node = node
15
- end
16
-
17
- end
18
- end
data/lib/nmap/hostname.rb DELETED
@@ -1,42 +0,0 @@
1
- module Nmap
2
- #
3
- # Represents a hostname.
4
- #
5
- # @since 0.7.0
6
- #
7
- class Hostname < Struct.new(:type, :name)
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
-
31
- #
32
- # Converts the hostname to a String.
33
- #
34
- # @return [String]
35
- # The name of the host.
36
- #
37
- def to_s
38
- self.name.to_s
39
- end
40
-
41
- end
42
- end