net-dns2 0.8.4 → 0.8.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +13 -5
- data/CHANGELOG.md +10 -0
- data/README.md +1 -1
- data/lib/net/dns/packet.rb +53 -48
- data/lib/net/dns/resolver.rb +84 -115
- data/net-dns.gemspec +4 -7
- metadata +15 -15
checksums.yaml
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
MjQ4ZDlmZjliMDEwZWU5NmYxMTIwOWQ3YTVlMTA3NzYxNTI2ODI5ZQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZWFhNmY0NDg3Mzc0NjIwZTQxYWY2ODRhNDRmYzI3MjM3NDZjYjcxOA==
|
5
7
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
YjE5MTc4ZjQ2ZmRiN2VhYThkNTIwYmYxODY3Nzg3NTM4YzFmMGY1NWRkZmNi
|
10
|
+
ZTRlZDgzMWM2OTFkZGM0OWExY2Y4NmEwMGRkZmJmMTIyNWY3MmNiODYzODhh
|
11
|
+
YTcwNTczNGI3OGUxNWMxYjc3YmIzYmRiNWM5NWFmZDYyYmFiNzE=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ODAxMGQ2ZWI3MWMxNGZlZWUyNDI2MmIzZDA2NGU3MmE3Zjc5NzgzYWNlYjk5
|
14
|
+
NmUyZTZlMDZmMjI5NTIyYjdkZjFlMjhkZThmYmI1MWNiNTkzOWRiYzMwODYx
|
15
|
+
MGM2MmJlYzAzMGE2ZDgxMGVkMDQ5MDIyZGFiMDJmNzRiZTkyYjY=
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## Release 0.8.5
|
4
|
+
- FIXED: Disable logger by default and change logger behaivior issue #20
|
5
|
+
- FIXED: Logger and log4j [feature request] issue #16
|
6
|
+
- FIXED: Resolver#logger= should not call close on old logger issue #3
|
7
|
+
- FIXED: Could not disable mac source_address spoofing, added option
|
8
|
+
- MERGED: Pull request #33, switches to enumerators
|
9
|
+
|
10
|
+
## Release 0.8.4
|
11
|
+
- FIXED: Missing file for new spf record, pull/57
|
12
|
+
|
3
13
|
## Release 0.8.3
|
4
14
|
- FIXED: Packet size cannot be set issue #1
|
5
15
|
- FIXED: Now raise exception if raw sockets are requested and we are not
|
data/README.md
CHANGED
data/lib/net/dns/packet.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'logger'
|
2
1
|
require 'net/dns/names'
|
3
2
|
require 'net/dns/header'
|
4
3
|
require 'net/dns/question'
|
@@ -65,18 +64,8 @@ module Net
|
|
65
64
|
#
|
66
65
|
# == Logging facility
|
67
66
|
#
|
68
|
-
#
|
69
|
-
#
|
70
|
-
# maybe want to override it or change the file descriptor.
|
71
|
-
#
|
72
|
-
# packet = Net::DNS::Packet.new("www.example.com")
|
73
|
-
# packet.logger = $stderr
|
74
|
-
#
|
75
|
-
# # or even
|
76
|
-
# packet.logger = Logger.new("/tmp/packet.log")
|
77
|
-
#
|
78
|
-
# If the <tt>Net::DNS::Packet</tt> class is directly instantiated by the <tt>Net::DNS::Resolver</tt>
|
79
|
-
# class, like the great majority of the time, it will use the same logger facility.
|
67
|
+
# Logger can be set by using logger= to set the logger to any object that implements
|
68
|
+
# the necessary functions. If no logger is set then no logging is performed.
|
80
69
|
#
|
81
70
|
# Logger level will be set to <tt>Logger::Debug</tt> if <tt>$DEBUG</tt> variable is set.
|
82
71
|
#
|
@@ -94,6 +83,7 @@ module Net
|
|
94
83
|
|
95
84
|
attr_reader :header, :question, :answer, :authority, :additional
|
96
85
|
attr_reader :answerfrom, :answersize
|
86
|
+
@@logger = nil
|
97
87
|
|
98
88
|
# Creates a new instance of <tt>Net::DNS::Packet</tt> class. Arguments are the
|
99
89
|
# canonical name of the resource, an optional type field and an optional
|
@@ -120,16 +110,39 @@ module Net
|
|
120
110
|
@answer = []
|
121
111
|
@authority = []
|
122
112
|
@additional = []
|
123
|
-
@logger = Logger.new $stdout
|
124
|
-
@logger.level = $DEBUG ? Logger::DEBUG : Logger::WARN
|
125
113
|
end
|
126
114
|
|
127
|
-
|
128
115
|
# Checks if the packet is a QUERY packet
|
129
116
|
def query?
|
130
117
|
@header.query?
|
131
118
|
end
|
132
119
|
|
120
|
+
def self.logger= logger
|
121
|
+
if logger.respond_to?(:warn) && logger.respond_to?(:debug) && logger.respond_to?(:info)
|
122
|
+
@@logger = logger
|
123
|
+
else
|
124
|
+
raise ArgumentError, "Invalid logger provided to #{self.class}"
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
def warn *args
|
129
|
+
if @@logger
|
130
|
+
@@logger.warn *args
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
def debug *args
|
135
|
+
if @@logger
|
136
|
+
@@logger.debug *args
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
def info *args
|
141
|
+
if @@logger
|
142
|
+
@@logger.info *args
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
133
146
|
# Returns the packet object in binary data, suitable
|
134
147
|
# for sending across a network stream.
|
135
148
|
#
|
@@ -347,6 +360,15 @@ module Net
|
|
347
360
|
end
|
348
361
|
end
|
349
362
|
|
363
|
+
# Filters the elements in the +answer+ section based on the class given
|
364
|
+
def elements(type = nil)
|
365
|
+
if type
|
366
|
+
@answer.select {|elem| elem.kind_of? type}
|
367
|
+
else
|
368
|
+
@answer
|
369
|
+
end
|
370
|
+
end
|
371
|
+
|
350
372
|
# Iterates every address in the +answer+ section
|
351
373
|
# of this <tt>Net::DNS::Packet</tt> instance.
|
352
374
|
#
|
@@ -357,10 +379,7 @@ module Net
|
|
357
379
|
# As you can see in the documentation for the <tt>Net::DNS::RR::A</tt> class,
|
358
380
|
# the address returned is an instance of <tt>IPAddr</tt> class.
|
359
381
|
def each_address(&block)
|
360
|
-
|
361
|
-
next unless elem.class == Net::DNS::RR::A
|
362
|
-
yield elem.address
|
363
|
-
end
|
382
|
+
elements(Net::DNS::RR::A).map(&:address).each(&block)
|
364
383
|
end
|
365
384
|
|
366
385
|
# Iterates every nameserver in the +answer+ section
|
@@ -371,10 +390,7 @@ module Net
|
|
371
390
|
# end
|
372
391
|
#
|
373
392
|
def each_nameserver(&block)
|
374
|
-
|
375
|
-
next unless elem.class == Net::DNS::RR::NS
|
376
|
-
yield elem.nsdname
|
377
|
-
end
|
393
|
+
elements(Net::DNS::RR::NS).map(&:nsdname).each(&block)
|
378
394
|
end
|
379
395
|
|
380
396
|
# Iterates every exchange record in the +answer+ section
|
@@ -385,10 +401,7 @@ module Net
|
|
385
401
|
# end
|
386
402
|
#
|
387
403
|
def each_mx(&block)
|
388
|
-
|
389
|
-
next unless elem.class == Net::DNS::RR::MX
|
390
|
-
yield elem.preference, elem.exchange
|
391
|
-
end
|
404
|
+
elements(Net::DNS::RR::MX).map{|elem| [elem.preference, elem.exchange]}.each(&block)
|
392
405
|
end
|
393
406
|
|
394
407
|
# Iterates every canonical name in the +answer+ section
|
@@ -399,10 +412,7 @@ module Net
|
|
399
412
|
# end
|
400
413
|
#
|
401
414
|
def each_cname(&block)
|
402
|
-
|
403
|
-
next unless elem.class == Net::DNS::RR::CNAME
|
404
|
-
yield elem.cname
|
405
|
-
end
|
415
|
+
elements(Net::DNS::RR::CNAME).map(&:cname).each(&block)
|
406
416
|
end
|
407
417
|
|
408
418
|
# Iterates every pointer in the +answer+ section
|
@@ -413,10 +423,7 @@ module Net
|
|
413
423
|
# end
|
414
424
|
#
|
415
425
|
def each_ptr(&block)
|
416
|
-
|
417
|
-
next unless elem.class == Net::DNS::RR::PTR
|
418
|
-
yield elem.ptrdname
|
419
|
-
end
|
426
|
+
elements(Net::DNS::RR::PTR).map(&:ptrdname).each(&block)
|
420
427
|
end
|
421
428
|
|
422
429
|
# Returns the packet size in bytes.
|
@@ -479,8 +486,6 @@ module Net
|
|
479
486
|
|
480
487
|
@answerfrom = from[2] + ":" + from[1].to_s
|
481
488
|
@answersize = data.size
|
482
|
-
@logger = Logger.new $stdout
|
483
|
-
@logger.level = $DEBUG ? Logger::DEBUG : Logger::WARN
|
484
489
|
|
485
490
|
#------------------------------------------------------------
|
486
491
|
# Header section
|
@@ -488,34 +493,34 @@ module Net
|
|
488
493
|
offset = Net::DNS::HFIXEDSZ
|
489
494
|
@header = Net::DNS::Header.parse(data[0..offset-1])
|
490
495
|
|
491
|
-
|
492
|
-
|
496
|
+
debug ";; HEADER SECTION"
|
497
|
+
debug @header.inspect
|
493
498
|
|
494
499
|
#------------------------------------------------------------
|
495
500
|
# Question section
|
496
501
|
#------------------------------------------------------------
|
497
502
|
section = @header.opCode == "UPDATE" ? "ZONE" : "QUESTION"
|
498
|
-
|
503
|
+
debug ";; #{section} SECTION (#{@header.qdCount} record#{@header.qdCount == 1 ? '': 's'})"
|
499
504
|
|
500
505
|
@question = []
|
501
506
|
@header.qdCount.times do
|
502
507
|
qobj,offset = parse_question(data,offset)
|
503
508
|
@question << qobj
|
504
|
-
|
509
|
+
debug ";; #{qobj.inspect}"
|
505
510
|
end
|
506
511
|
|
507
512
|
#------------------------------------------------------------
|
508
513
|
# Answer/prerequisite section
|
509
514
|
#------------------------------------------------------------
|
510
515
|
section = @header.opCode == "UPDATE" ? "PREREQUISITE" : "ANSWER"
|
511
|
-
|
516
|
+
debug ";; #{section} SECTION (#{@header.qdCount} record#{@header.qdCount == 1 ? '': 's'})"
|
512
517
|
|
513
518
|
@answer = []
|
514
519
|
@header.anCount.times do
|
515
520
|
begin
|
516
521
|
rrobj,offset = Net::DNS::RR.parse_packet(data,offset)
|
517
522
|
@answer << rrobj
|
518
|
-
|
523
|
+
debug rrobj.inspect
|
519
524
|
rescue NameError => e
|
520
525
|
warn "Net::DNS unsupported record type: #{e.message}"
|
521
526
|
end
|
@@ -525,14 +530,14 @@ module Net
|
|
525
530
|
# Authority/update section
|
526
531
|
#------------------------------------------------------------
|
527
532
|
section = @header.opCode == "UPDATE" ? "UPDATE" : "AUTHORITY"
|
528
|
-
|
533
|
+
debug ";; #{section} SECTION (#{@header.nsCount} record#{@header.nsCount == 1 ? '': 's'})"
|
529
534
|
|
530
535
|
@authority = []
|
531
536
|
@header.nsCount.times do
|
532
537
|
begin
|
533
538
|
rrobj,offset = Net::DNS::RR.parse_packet(data,offset)
|
534
539
|
@authority << rrobj
|
535
|
-
|
540
|
+
debug rrobj.inspect
|
536
541
|
rescue NameError => e
|
537
542
|
warn "Net::DNS unsupported record type: #{e.message}"
|
538
543
|
end
|
@@ -541,14 +546,14 @@ module Net
|
|
541
546
|
#------------------------------------------------------------
|
542
547
|
# Additional section
|
543
548
|
#------------------------------------------------------------
|
544
|
-
|
549
|
+
debug ";; ADDITIONAL SECTION (#{@header.arCount} record#{@header.arCount == 1 ? '': 's'})"
|
545
550
|
|
546
551
|
@additional = []
|
547
552
|
@header.arCount.times do
|
548
553
|
begin
|
549
554
|
rrobj,offset = Net::DNS::RR.parse_packet(data,offset)
|
550
555
|
@additional << rrobj
|
551
|
-
|
556
|
+
debug rrobj.inspect
|
552
557
|
rescue NameError => e
|
553
558
|
warn "Net::DNS unsupported record type: #{e.message}"
|
554
559
|
end
|
data/lib/net/dns/resolver.rb
CHANGED
@@ -29,9 +29,6 @@ end
|
|
29
29
|
|
30
30
|
module Net
|
31
31
|
module DNS
|
32
|
-
|
33
|
-
include Logger::Severity
|
34
|
-
|
35
32
|
# = Net::DNS::Resolver - DNS resolver class
|
36
33
|
#
|
37
34
|
# The Net::DNS::Resolver class implements a complete DNS resolver written
|
@@ -102,7 +99,6 @@ module Net
|
|
102
99
|
# explanation of its usage.
|
103
100
|
Defaults = {
|
104
101
|
:config_file => "/etc/resolv.conf",
|
105
|
-
:log_file => $stdout,
|
106
102
|
:port => 53,
|
107
103
|
:searchlist => [],
|
108
104
|
:nameservers => [IPAddr.new("127.0.0.1")],
|
@@ -110,6 +106,7 @@ module Net
|
|
110
106
|
:source_port => 0,
|
111
107
|
:source_address => IPAddr.new("0.0.0.0"),
|
112
108
|
:source_address_inet6 => IPAddr.new('::'),
|
109
|
+
:spoof_mac => false,
|
113
110
|
:interface => "eth0",
|
114
111
|
:retry_interval => 5,
|
115
112
|
:retry_number => 4,
|
@@ -123,6 +120,7 @@ module Net
|
|
123
120
|
:udp_timeout => UdpTimeout.new(5),
|
124
121
|
}
|
125
122
|
|
123
|
+
@@logger = nil
|
126
124
|
|
127
125
|
class << self
|
128
126
|
|
@@ -246,10 +244,6 @@ module Net
|
|
246
244
|
@config = Defaults.merge config
|
247
245
|
@raw = false
|
248
246
|
|
249
|
-
# New logger facility
|
250
|
-
@logger = Logger.new(@config[:log_file])
|
251
|
-
@logger.level = $DEBUG ? Logger::DEBUG : Logger::WARN
|
252
|
-
|
253
247
|
#------------------------------------------------------------
|
254
248
|
# Resolver configuration will be set in order from:
|
255
249
|
# 1) initialize arguments
|
@@ -274,7 +268,7 @@ module Net
|
|
274
268
|
# Parsing arguments
|
275
269
|
#------------------------------------------------------------
|
276
270
|
config.each do |key,val|
|
277
|
-
next if key == :
|
271
|
+
next if key == :config_file
|
278
272
|
begin
|
279
273
|
eval "self.#{key.to_s} = val"
|
280
274
|
rescue NoMethodError
|
@@ -283,6 +277,35 @@ module Net
|
|
283
277
|
end
|
284
278
|
end
|
285
279
|
|
280
|
+
attr_accessor :spoof_mac
|
281
|
+
|
282
|
+
def self.logger= logger
|
283
|
+
if logger.respond_to?(:warn) && logger.respond_to?(:debug) && logger.respond_to?(:info)
|
284
|
+
@@logger = logger
|
285
|
+
else
|
286
|
+
raise ArgumentError, "Invalid logger provided to #{self.class}"
|
287
|
+
end
|
288
|
+
end
|
289
|
+
|
290
|
+
def warn *args
|
291
|
+
if @@logger
|
292
|
+
@@logger.warn *args
|
293
|
+
end
|
294
|
+
end
|
295
|
+
|
296
|
+
def debug *args
|
297
|
+
if @@logger
|
298
|
+
@debug *args
|
299
|
+
end
|
300
|
+
end
|
301
|
+
|
302
|
+
def info *args
|
303
|
+
if @@logger
|
304
|
+
@@logger.info *args
|
305
|
+
end
|
306
|
+
end
|
307
|
+
|
308
|
+
|
286
309
|
# Get the resolver search list, returned as an array of entries.
|
287
310
|
#
|
288
311
|
# res.searchlist
|
@@ -310,10 +333,10 @@ module Net
|
|
310
333
|
case arg
|
311
334
|
when String
|
312
335
|
@config[:searchlist] = [arg] if valid? arg
|
313
|
-
|
336
|
+
info "Searchlist changed to value #{@config[:searchlist].inspect}"
|
314
337
|
when Array
|
315
338
|
@config[:searchlist] = arg if arg.all? {|x| valid? x}
|
316
|
-
|
339
|
+
info "Searchlist changed to value #{@config[:searchlist].inspect}"
|
317
340
|
else
|
318
341
|
raise ArgumentError, "Wrong argument format, neither String nor Array"
|
319
342
|
end
|
@@ -346,7 +369,7 @@ module Net
|
|
346
369
|
#
|
347
370
|
def nameservers=(arg)
|
348
371
|
@config[:nameservers] = convert_nameservers_arg_to_ips(arg)
|
349
|
-
|
372
|
+
info "Nameservers list changed to value #{@config[:nameservers].inspect}"
|
350
373
|
end
|
351
374
|
alias_method("nameserver=","nameservers=")
|
352
375
|
|
@@ -368,7 +391,7 @@ module Net
|
|
368
391
|
def packet_size=(arg)
|
369
392
|
if arg.respond_to? :to_i
|
370
393
|
@config[:packet_size] = arg.to_i
|
371
|
-
|
394
|
+
info "Packet size changed to value #{@config[:packet_size].inspect}"
|
372
395
|
else
|
373
396
|
@logger.error "Packet size not set, #{arg.class} does not respond to to_i"
|
374
397
|
end
|
@@ -392,7 +415,7 @@ module Net
|
|
392
415
|
def port=(num)
|
393
416
|
if (0..65535).include? num
|
394
417
|
@config[:port] = num
|
395
|
-
|
418
|
+
info "Port number changed to #{num}"
|
396
419
|
else
|
397
420
|
raise ArgumentError, "Wrong port number #{num}"
|
398
421
|
end
|
@@ -479,17 +502,17 @@ module Net
|
|
479
502
|
|
480
503
|
begin
|
481
504
|
port = rand(64000)+1024
|
482
|
-
|
505
|
+
info "Try to determine state of source address #{addr} with port #{port}"
|
483
506
|
a = TCPServer.new(addr.to_s,port)
|
484
507
|
rescue SystemCallError => e
|
485
508
|
case e.errno
|
486
509
|
when 98 # Port already in use!
|
487
|
-
|
510
|
+
info "Port already in use"
|
488
511
|
retry
|
489
512
|
when 99 # Address is not valid: raw socket
|
490
513
|
if Process.uid == 0
|
491
514
|
@raw = true
|
492
|
-
|
515
|
+
info "Using raw sockets"
|
493
516
|
else
|
494
517
|
raise RuntimeError, "Raw sockets requested but not running as root."
|
495
518
|
end
|
@@ -503,10 +526,10 @@ module Net
|
|
503
526
|
case addr
|
504
527
|
when String
|
505
528
|
@config[:source_address] = IPAddr.new(addr)
|
506
|
-
|
529
|
+
info "Using new source address: #{@config[:source_address]}"
|
507
530
|
when IPAddr
|
508
531
|
@config[:source_address] = addr
|
509
|
-
|
532
|
+
info "Using new source address: #{@config[:source_address]}"
|
510
533
|
else
|
511
534
|
raise ArgumentError, "Unknown dest_address format"
|
512
535
|
end
|
@@ -528,7 +551,7 @@ module Net
|
|
528
551
|
def retry_interval=(num)
|
529
552
|
if num > 0
|
530
553
|
@config[:retry_interval] = num
|
531
|
-
|
554
|
+
info "Retransmission interval changed to #{num} seconds"
|
532
555
|
else
|
533
556
|
raise ArgumentError, "Interval must be positive"
|
534
557
|
end
|
@@ -548,7 +571,7 @@ module Net
|
|
548
571
|
def retry_number=(num)
|
549
572
|
if num.kind_of? Integer and num > 0
|
550
573
|
@config[:retry_number] = num
|
551
|
-
|
574
|
+
info "Retrasmissions number changed to #{num}"
|
552
575
|
else
|
553
576
|
raise ArgumentError, "Retry value must be a positive integer"
|
554
577
|
end
|
@@ -577,7 +600,7 @@ module Net
|
|
577
600
|
case bool
|
578
601
|
when TrueClass,FalseClass
|
579
602
|
@config[:recursive] = bool
|
580
|
-
|
603
|
+
info("Recursive state changed to #{bool}")
|
581
604
|
else
|
582
605
|
raise ArgumentError, "Argument must be boolean"
|
583
606
|
end
|
@@ -629,7 +652,7 @@ module Net
|
|
629
652
|
case bool
|
630
653
|
when TrueClass,FalseClass
|
631
654
|
@config[:defname] = bool
|
632
|
-
|
655
|
+
info("Defname state changed to #{bool}")
|
633
656
|
else
|
634
657
|
raise ArgumentError, "Argument must be boolean"
|
635
658
|
end
|
@@ -648,7 +671,7 @@ module Net
|
|
648
671
|
case bool
|
649
672
|
when TrueClass,FalseClass
|
650
673
|
@config[:dns_search] = bool
|
651
|
-
|
674
|
+
info("DNS search state changed to #{bool}")
|
652
675
|
else
|
653
676
|
raise ArgumentError, "Argument must be boolean"
|
654
677
|
end
|
@@ -677,7 +700,7 @@ module Net
|
|
677
700
|
case bool
|
678
701
|
when TrueClass,FalseClass
|
679
702
|
@config[:use_tcp] = bool
|
680
|
-
|
703
|
+
info("Use tcp flag changed to #{bool}")
|
681
704
|
else
|
682
705
|
raise ArgumentError, "Argument must be boolean"
|
683
706
|
end
|
@@ -693,7 +716,7 @@ module Net
|
|
693
716
|
case bool
|
694
717
|
when TrueClass,FalseClass
|
695
718
|
@config[:ignore_truncated] = bool
|
696
|
-
|
719
|
+
info("Ignore truncated flag changed to #{bool}")
|
697
720
|
else
|
698
721
|
raise ArgumentError, "Argument must be boolean"
|
699
722
|
end
|
@@ -729,7 +752,7 @@ module Net
|
|
729
752
|
#
|
730
753
|
def tcp_timeout=(secs)
|
731
754
|
@config[:tcp_timeout] = TcpTimeout.new(secs)
|
732
|
-
|
755
|
+
info("New TCP timeout value: #{@config[:tcp_timeout]} seconds")
|
733
756
|
end
|
734
757
|
|
735
758
|
# Return an object representing the value of the stored UDP
|
@@ -765,69 +788,7 @@ module Net
|
|
765
788
|
#
|
766
789
|
def udp_timeout=(secs)
|
767
790
|
@config[:udp_timeout] = UdpTimeout.new(secs)
|
768
|
-
|
769
|
-
end
|
770
|
-
|
771
|
-
# Set a new log file for the logger facility of the resolver
|
772
|
-
# class. Could be a file descriptor too:
|
773
|
-
#
|
774
|
-
# res.log_file = $stderr
|
775
|
-
#
|
776
|
-
# Note that a new logging facility will be create, destroing
|
777
|
-
# the old one, which will then be impossibile to recover.
|
778
|
-
#
|
779
|
-
def log_file=(log)
|
780
|
-
@logger.close
|
781
|
-
@config[:log_file] = log
|
782
|
-
@logger = Logger.new(@config[:log_file])
|
783
|
-
@logger.level = $DEBUG ? Logger::DEBUG : Logger::WARN
|
784
|
-
end
|
785
|
-
|
786
|
-
# This one permits to have a personal logger facility to handle
|
787
|
-
# resolver messages, instead of new built-in one, which is set up
|
788
|
-
# for a +$stdout+ (or +$stderr+) use.
|
789
|
-
#
|
790
|
-
# If you want your own logging facility you can create a new instance
|
791
|
-
# of the +Logger+ class:
|
792
|
-
#
|
793
|
-
# log = Logger.new("/tmp/resolver.log","weekly",2*1024*1024)
|
794
|
-
# log.level = Logger::DEBUG
|
795
|
-
# log.progname = "ruby_resolver"
|
796
|
-
#
|
797
|
-
# and then pass it to the resolver:
|
798
|
-
#
|
799
|
-
# res.logger = log
|
800
|
-
#
|
801
|
-
# Note that this will destroy the precedent logger.
|
802
|
-
#
|
803
|
-
def logger=(logger)
|
804
|
-
if logger.kind_of? Logger
|
805
|
-
@logger.close
|
806
|
-
@logger = logger
|
807
|
-
else
|
808
|
-
raise ArgumentError, "Argument must be an instance of Logger class"
|
809
|
-
end
|
810
|
-
end
|
811
|
-
|
812
|
-
# Set the log level for the built-in logging facility.
|
813
|
-
#
|
814
|
-
# The log level can be one of the following:
|
815
|
-
#
|
816
|
-
# - +Net::DNS::DEBUG+
|
817
|
-
# - +Net::DNS::INFO+
|
818
|
-
# - +Net::DNS::WARN+
|
819
|
-
# - +Net::DNS::ERROR+
|
820
|
-
# - +Net::DNS::FATAL+
|
821
|
-
#
|
822
|
-
# Note that if the global variable $DEBUG is set (like when the
|
823
|
-
# -d switch is used at the command line) the logger level is
|
824
|
-
# automatically set at DEGUB.
|
825
|
-
#
|
826
|
-
# For further informations, see Logger documentation in the
|
827
|
-
# Ruby standard library.
|
828
|
-
#
|
829
|
-
def log_level=(level)
|
830
|
-
@logger.level = level
|
791
|
+
info("New UDP timeout value: #{@config[:udp_timeout]} seconds")
|
831
792
|
end
|
832
793
|
|
833
794
|
# Performs a DNS query for the given name, applying the searchlist if
|
@@ -861,7 +822,7 @@ module Net
|
|
861
822
|
|
862
823
|
# If the name contains at least one dot then try it as is first.
|
863
824
|
if name.include? "."
|
864
|
-
|
825
|
+
debug "Search(#{name},#{Net::DNS::RR::Types.new(type)},#{Net::DNS::RR::Classes.new(cls)})"
|
865
826
|
ans = query(name,type,cls)
|
866
827
|
return ans if ans.header.anCount > 0
|
867
828
|
end
|
@@ -870,14 +831,14 @@ module Net
|
|
870
831
|
if name !~ /\.$/ and @config[:dns_search]
|
871
832
|
@config[:searchlist].each do |domain|
|
872
833
|
newname = name + "." + domain
|
873
|
-
|
834
|
+
debug "Search(#{newname},#{Net::DNS::RR::Types.new(type)},#{Net::DNS::RR::Classes.new(cls)})"
|
874
835
|
ans = query(newname,type,cls)
|
875
836
|
return ans if ans.header.anCount > 0
|
876
837
|
end
|
877
838
|
end
|
878
839
|
|
879
840
|
# Finally, if the name has no dots then try it as is.
|
880
|
-
|
841
|
+
debug "Search(#{name},#{Net::DNS::RR::Types.new(type)},#{Net::DNS::RR::Classes.new(cls)})"
|
881
842
|
query(name+".",type,cls)
|
882
843
|
|
883
844
|
end
|
@@ -915,7 +876,7 @@ module Net
|
|
915
876
|
name += "." + @config[:domain]
|
916
877
|
end
|
917
878
|
|
918
|
-
|
879
|
+
debug "Query(#{name},#{Net::DNS::RR::Types.new(type)},#{Net::DNS::RR::Classes.new(cls)})"
|
919
880
|
|
920
881
|
send(name,type,cls)
|
921
882
|
|
@@ -970,31 +931,31 @@ module Net
|
|
970
931
|
# Choose whether use TCP, UDP or RAW
|
971
932
|
if packet_size > @config[:packet_size] # Must use TCP, either plain or raw
|
972
933
|
if @raw # Use raw sockets?
|
973
|
-
|
934
|
+
info "Sending #{packet_size} bytes using TCP over RAW socket"
|
974
935
|
method = :send_raw_tcp
|
975
936
|
else
|
976
|
-
|
937
|
+
info "Sending #{packet_size} bytes using TCP"
|
977
938
|
method = :query_tcp
|
978
939
|
end
|
979
940
|
else # Packet size is inside the boundaries
|
980
941
|
if @raw # Use raw sockets?
|
981
|
-
|
942
|
+
info "Sending #{packet_size} bytes using UDP over RAW socket"
|
982
943
|
method = :send_raw_udp
|
983
944
|
elsif use_tcp? # User requested TCP
|
984
|
-
|
945
|
+
info "Sending #{packet_size} bytes using TCP"
|
985
946
|
method = :query_tcp
|
986
947
|
else # Finally use UDP
|
987
|
-
|
948
|
+
info "Sending #{packet_size} bytes using UDP"
|
988
949
|
method = :query_udp
|
989
950
|
end
|
990
951
|
end
|
991
952
|
|
992
953
|
if type == Net::DNS::AXFR
|
993
954
|
if @raw
|
994
|
-
|
955
|
+
info "AXFR query, switching to TCP over RAW socket"
|
995
956
|
method = :send_raw_tcp
|
996
957
|
else
|
997
|
-
|
958
|
+
info "AXFR query, switching to TCP"
|
998
959
|
method = :query_tcp
|
999
960
|
end
|
1000
961
|
end
|
@@ -1013,11 +974,11 @@ module Net
|
|
1013
974
|
raise NoResponseError, message
|
1014
975
|
end
|
1015
976
|
|
1016
|
-
|
977
|
+
info "Received #{ans[0].size} bytes from #{ans[1][2]+":"+ans[1][1].to_s}"
|
1017
978
|
response = Net::DNS::Packet.parse(ans[0],ans[1])
|
1018
979
|
|
1019
980
|
if response.header.truncated? and not ignore_truncated?
|
1020
|
-
|
981
|
+
info "Packet truncated, retrying using TCP"
|
1021
982
|
self.use_tcp = true
|
1022
983
|
begin
|
1023
984
|
return query(argument,type,cls)
|
@@ -1035,7 +996,7 @@ module Net
|
|
1035
996
|
# since it is using the same infrastucture.
|
1036
997
|
#
|
1037
998
|
def axfr(name, cls = Net::DNS::IN)
|
1038
|
-
|
999
|
+
info "Requested AXFR transfer, zone #{name} class #{cls}"
|
1039
1000
|
query(name, Net::DNS::AXFR, cls)
|
1040
1001
|
end
|
1041
1002
|
|
@@ -1173,15 +1134,15 @@ module Net
|
|
1173
1134
|
|
1174
1135
|
@config[:tcp_timeout].timeout do
|
1175
1136
|
socket.connect(sockaddr)
|
1176
|
-
|
1137
|
+
info "Contacting nameserver #{ns} port #{@config[:port]}"
|
1177
1138
|
socket.write(length+packet_data)
|
1178
1139
|
ans = socket.recv(Net::DNS::INT16SZ)
|
1179
1140
|
len = ans.unpack("n")[0]
|
1180
1141
|
|
1181
|
-
|
1142
|
+
info "Receiving #{len} bytes..."
|
1182
1143
|
|
1183
1144
|
if len == 0
|
1184
|
-
|
1145
|
+
info "Receiving 0 lenght packet from nameserver #{ns}, trying next."
|
1185
1146
|
next
|
1186
1147
|
end
|
1187
1148
|
|
@@ -1192,13 +1153,13 @@ module Net
|
|
1192
1153
|
end
|
1193
1154
|
|
1194
1155
|
unless buffer.size == len
|
1195
|
-
|
1156
|
+
info "Malformed packet from nameserver #{ns}, trying next."
|
1196
1157
|
next
|
1197
1158
|
end
|
1198
1159
|
end
|
1199
1160
|
return [buffer,["",@config[:port],ns.to_s,ns.to_s]]
|
1200
1161
|
rescue TimeoutError
|
1201
|
-
|
1162
|
+
info "Nameserver #{ns} not responding within TCP timeout, trying next one"
|
1202
1163
|
next
|
1203
1164
|
ensure
|
1204
1165
|
socket.close
|
@@ -1220,7 +1181,7 @@ module Net
|
|
1220
1181
|
@config[:nameservers].each do |ns|
|
1221
1182
|
begin
|
1222
1183
|
@config[:udp_timeout].timeout do
|
1223
|
-
|
1184
|
+
info "Contacting nameserver #{ns} port #{@config[:port]}"
|
1224
1185
|
ans = if ns.ipv6?
|
1225
1186
|
socket6.send(packet_data, 0, ns.to_s, @config[:port])
|
1226
1187
|
socket6.recvfrom(@config[:packet_size])
|
@@ -1231,7 +1192,7 @@ module Net
|
|
1231
1192
|
end
|
1232
1193
|
break if ans
|
1233
1194
|
rescue TimeoutError
|
1234
|
-
|
1195
|
+
info "Nameserver #{ns} not responding within UDP timeout, trying next one"
|
1235
1196
|
next
|
1236
1197
|
end
|
1237
1198
|
end
|
@@ -1248,13 +1209,17 @@ module Net
|
|
1248
1209
|
octet.read_quad @config[:source_address].to_s
|
1249
1210
|
packet.ip_src = octet
|
1250
1211
|
packet.udp_src =rand(0xffff-1024) + 1024
|
1251
|
-
|
1212
|
+
if @config[:spoof_mac]
|
1213
|
+
packet.eth_saddr = PacketFu::Utils.arp(@config[:source_address].to_s, {iface: @config[:interface]})
|
1214
|
+
end
|
1252
1215
|
elsif @config[:source_address_inet6]
|
1253
1216
|
octet = PacketFu::Octets.new
|
1254
1217
|
octet.read_quad @config[:source_address_inet6].to_s
|
1255
1218
|
packet.ip_src = octet
|
1256
1219
|
packet.udp_src = @config[:source_address_inet6].to_i
|
1257
|
-
|
1220
|
+
if @config[:spoof_mac]
|
1221
|
+
packet.eth_saddr = PacketFu::Utils.arp(@config[:source_address_inet6].to_s, {iface: @config[:interface]})
|
1222
|
+
end
|
1258
1223
|
else
|
1259
1224
|
raise ArgumentError, "No source address specified, cannot send"
|
1260
1225
|
end
|
@@ -1281,13 +1246,17 @@ module Net
|
|
1281
1246
|
octet.read_quad @config[:source_address].to_s
|
1282
1247
|
packet.ip_src = octet
|
1283
1248
|
packet.udp_src =rand(0xffff-1024) + 1024
|
1284
|
-
|
1249
|
+
if @config[:spoof_mac]
|
1250
|
+
packet.eth_saddr = PacketFu::Utils.arp(@config[:source_address].to_s, {iface: @config[:interface]})
|
1251
|
+
end
|
1285
1252
|
elsif @config[:source_address_inet6]
|
1286
1253
|
octet = PacketFu::Octets.new
|
1287
1254
|
octet.read_quad @config[:source_address_inet6].to_s
|
1288
1255
|
packet.ip_src = octet
|
1289
1256
|
packet.udp_src = @config[:source_address_inet6].to_i
|
1290
|
-
|
1257
|
+
if @config[:spoof_mac]
|
1258
|
+
packet.eth_saddr = PacketFu::Utils.arp(@config[:source_address_inet6].to_s, {iface: @config[:interface]})
|
1259
|
+
end
|
1291
1260
|
else
|
1292
1261
|
raise ArgumentError, "No source address specified, cannot send"
|
1293
1262
|
end
|
data/net-dns.gemspec
CHANGED
@@ -1,12 +1,14 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
|
3
|
+
require 'date'
|
4
|
+
|
3
5
|
Gem::Specification.new do |s|
|
4
6
|
s.name = "net-dns2"
|
5
|
-
s.version = "0.8.
|
7
|
+
s.version = "0.8.5"
|
6
8
|
|
7
9
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
10
|
s.authors = ["Marco Ceresa", "Simone Carletti", "Christopher Carpenter"]
|
9
|
-
s.date =
|
11
|
+
s.date = Date.today.to_s
|
10
12
|
s.description = "Net::DNS is a pure Ruby DNS library, with a clean OO interface and an extensible API. The net-dns2 ruby gem is an actively maintained fork of the original net-dns."
|
11
13
|
s.email = "mordocai@mordocai.net"
|
12
14
|
s.files = [
|
@@ -26,11 +28,6 @@ Gem::Specification.new do |s|
|
|
26
28
|
s.homepage = "http://github.com/mordocai/net-dns"
|
27
29
|
s.require_paths = ["lib"]
|
28
30
|
s.summary = "Pure Ruby DNS library, fork with fixes."
|
29
|
-
# s.test_files = [
|
30
|
-
# "spec/fixtures/resolv.conf", "spec/resolver_spec.rb", "spec/spec_helper.rb",
|
31
|
-
# "spec/unit/resolver/dns_timeout_spec.rb", "spec/unit/tcp_timeout_spec.rb",
|
32
|
-
# "spec/unit/udp_timeout_spec.rb"
|
33
|
-
# ]
|
34
31
|
s.required_ruby_version = Gem::Requirement.new(">= 1.9.2")
|
35
32
|
s.license = 'Ruby'
|
36
33
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: net-dns2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marco Ceresa
|
@@ -10,62 +10,62 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2014-
|
13
|
+
date: 2014-08-28 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rake
|
17
17
|
requirement: !ruby/object:Gem::Requirement
|
18
18
|
requirements:
|
19
|
-
- -
|
19
|
+
- - ~>
|
20
20
|
- !ruby/object:Gem::Version
|
21
21
|
version: '10.0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
requirements:
|
26
|
-
- -
|
26
|
+
- - ~>
|
27
27
|
- !ruby/object:Gem::Version
|
28
28
|
version: '10.0'
|
29
29
|
- !ruby/object:Gem::Dependency
|
30
30
|
name: yard
|
31
31
|
requirement: !ruby/object:Gem::Requirement
|
32
32
|
requirements:
|
33
|
-
- -
|
33
|
+
- - ! '>='
|
34
34
|
- !ruby/object:Gem::Version
|
35
35
|
version: '0'
|
36
36
|
type: :development
|
37
37
|
prerelease: false
|
38
38
|
version_requirements: !ruby/object:Gem::Requirement
|
39
39
|
requirements:
|
40
|
-
- -
|
40
|
+
- - ! '>='
|
41
41
|
- !ruby/object:Gem::Version
|
42
42
|
version: '0'
|
43
43
|
- !ruby/object:Gem::Dependency
|
44
44
|
name: rspec
|
45
45
|
requirement: !ruby/object:Gem::Requirement
|
46
46
|
requirements:
|
47
|
-
- -
|
47
|
+
- - ! '>='
|
48
48
|
- !ruby/object:Gem::Version
|
49
49
|
version: '0'
|
50
50
|
type: :development
|
51
51
|
prerelease: false
|
52
52
|
version_requirements: !ruby/object:Gem::Requirement
|
53
53
|
requirements:
|
54
|
-
- -
|
54
|
+
- - ! '>='
|
55
55
|
- !ruby/object:Gem::Version
|
56
56
|
version: '0'
|
57
57
|
- !ruby/object:Gem::Dependency
|
58
58
|
name: packetfu
|
59
59
|
requirement: !ruby/object:Gem::Requirement
|
60
60
|
requirements:
|
61
|
-
- -
|
61
|
+
- - ! '>='
|
62
62
|
- !ruby/object:Gem::Version
|
63
63
|
version: '0'
|
64
64
|
type: :runtime
|
65
65
|
prerelease: false
|
66
66
|
version_requirements: !ruby/object:Gem::Requirement
|
67
67
|
requirements:
|
68
|
-
- -
|
68
|
+
- - ! '>='
|
69
69
|
- !ruby/object:Gem::Version
|
70
70
|
version: '0'
|
71
71
|
description: Net::DNS is a pure Ruby DNS library, with a clean OO interface and an
|
@@ -76,8 +76,8 @@ executables: []
|
|
76
76
|
extensions: []
|
77
77
|
extra_rdoc_files: []
|
78
78
|
files:
|
79
|
-
-
|
80
|
-
-
|
79
|
+
- .gitignore
|
80
|
+
- .travis.yml
|
81
81
|
- CHANGELOG.md
|
82
82
|
- Gemfile
|
83
83
|
- README.md
|
@@ -122,17 +122,17 @@ require_paths:
|
|
122
122
|
- lib
|
123
123
|
required_ruby_version: !ruby/object:Gem::Requirement
|
124
124
|
requirements:
|
125
|
-
- -
|
125
|
+
- - ! '>='
|
126
126
|
- !ruby/object:Gem::Version
|
127
127
|
version: 1.9.2
|
128
128
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
129
|
requirements:
|
130
|
-
- -
|
130
|
+
- - ! '>='
|
131
131
|
- !ruby/object:Gem::Version
|
132
132
|
version: '0'
|
133
133
|
requirements: []
|
134
134
|
rubyforge_project:
|
135
|
-
rubygems_version: 2.
|
135
|
+
rubygems_version: 2.2.2
|
136
136
|
signing_key:
|
137
137
|
specification_version: 4
|
138
138
|
summary: Pure Ruby DNS library, fork with fixes.
|