net-dns 0.1 → 0.2
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.
- data/InstalledFiles +1 -0
- data/Rakefile +3 -1
- data/lib/net/dns/resolver.rb +39 -84
- data/lib/net/dns/rr.rb +6 -1
- metadata +3 -2
data/InstalledFiles
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
/usr/local/lib/site_ruby/1.8/net/dns/resolver.rb
|
data/Rakefile
CHANGED
@@ -6,6 +6,8 @@ require 'rake/gempackagetask'
|
|
6
6
|
|
7
7
|
require 'rubygems'
|
8
8
|
|
9
|
+
$VERSION = 0.2
|
10
|
+
|
9
11
|
desc "Run the tests"
|
10
12
|
Rake::TestTask.new do |t|
|
11
13
|
t.libs << "test"
|
@@ -29,7 +31,7 @@ end
|
|
29
31
|
#
|
30
32
|
SPEC = Gem::Specification.new do |s|
|
31
33
|
s.name = "net-dns"
|
32
|
-
s.version = "
|
34
|
+
s.version = "#$VERSION"
|
33
35
|
s.author = "Marco Ceresa"
|
34
36
|
s.email = "ceresa@gmail.com"
|
35
37
|
s.homepage = "http://net-dns.rubyforge.org/"
|
data/lib/net/dns/resolver.rb
CHANGED
@@ -243,70 +243,6 @@ module Net # :nodoc:
|
|
243
243
|
end
|
244
244
|
end
|
245
245
|
|
246
|
-
def Resolver.cname_addr(names,packet)
|
247
|
-
addr = []
|
248
|
-
oct2 = RegExp.new('(?:2[0-4]\d|25[0-5]|[0-1]?\d\d|\d)')
|
249
|
-
|
250
|
-
packet.answer.each do |rr|
|
251
|
-
next unless begin
|
252
|
-
ret = false
|
253
|
-
names.each {|x| ret = true if rr.name.include? x}
|
254
|
-
ret
|
255
|
-
end
|
256
|
-
if rr.type == Net::DNS::CNAME
|
257
|
-
names.push(rr.cname)
|
258
|
-
elsif rr.type == Net::DNS::A
|
259
|
-
next unless rr.address =~ /^(#{oct2}\.#{oct2}\.#{oct2}\.#{oct2})$/
|
260
|
-
addr.push($1)
|
261
|
-
end
|
262
|
-
end
|
263
|
-
addr
|
264
|
-
end
|
265
|
-
|
266
|
-
def _packetsz
|
267
|
-
if @udppacketsize > Net::DNS::PACKETSZ
|
268
|
-
@udppacketsize
|
269
|
-
else
|
270
|
-
Net::DNS::PACKETSZ
|
271
|
-
end
|
272
|
-
end
|
273
|
-
|
274
|
-
def send_tcp(packet, packet_data)
|
275
|
-
if @nameservers.size == 0
|
276
|
-
@errorstring = "no nameservers"
|
277
|
-
puts ";; ERROR: send_tcp: no nameservers\n" if $DEBUG
|
278
|
-
return nil # ?
|
279
|
-
end
|
280
|
-
|
281
|
-
self._reset_errorstring
|
282
|
-
|
283
|
-
timeout = @tcp_timeout
|
284
|
-
|
285
|
-
@nameservers.each do |ns|
|
286
|
-
srcport = @srcport
|
287
|
-
srcaddr = @srcaddr
|
288
|
-
dstport = @port
|
289
|
-
|
290
|
-
puts ";; send_tcp(#{ns}:#{dstport}) (src port = #{srcport})" if $DEBUG
|
291
|
-
|
292
|
-
sock = TCPSocket.new(ns,dstport)
|
293
|
-
|
294
|
-
# TODO !!!
|
295
|
-
end
|
296
|
-
end
|
297
|
-
|
298
|
-
end
|
299
|
-
end
|
300
|
-
end
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
module Net
|
307
|
-
module DNS
|
308
|
-
class Resolver
|
309
|
-
|
310
246
|
# Get the resolver searchlist, returned as an array of entries
|
311
247
|
#
|
312
248
|
# res.searchlist
|
@@ -353,7 +289,7 @@ module Net
|
|
353
289
|
@config[:nameservers].each do |x|
|
354
290
|
arr << x.to_s
|
355
291
|
end
|
356
|
-
arr
|
292
|
+
arr
|
357
293
|
end
|
358
294
|
alias_method :nameserver, :nameservers
|
359
295
|
|
@@ -818,7 +754,7 @@ module Net
|
|
818
754
|
@logger.close
|
819
755
|
@config[:log_file] = log
|
820
756
|
@logger = Logger.new(@config[:log_file])
|
821
|
-
@logger.level = $DEBUG ? Logger::
|
757
|
+
@logger.level = $DEBUG ? Logger::DEBUG : Logger::WARN
|
822
758
|
end
|
823
759
|
|
824
760
|
# This one permits to have a personal logger facility to handle
|
@@ -1019,16 +955,23 @@ module Net
|
|
1019
955
|
# Parse a configuration file specified as the argument.
|
1020
956
|
#
|
1021
957
|
def parse_config_file
|
1022
|
-
|
1023
|
-
|
1024
|
-
|
1025
|
-
|
1026
|
-
|
1027
|
-
|
1028
|
-
|
1029
|
-
|
1030
|
-
|
1031
|
-
|
958
|
+
if RUBY_PLATFORM =~ /win/
|
959
|
+
require 'win32/resolv'
|
960
|
+
arr = Win32::Resolv.get_resolv_info
|
961
|
+
self.domain = arr[0]
|
962
|
+
self.nameservers = arr[1]
|
963
|
+
else
|
964
|
+
IO.foreach(@config[:config_file]) do |line|
|
965
|
+
line.gsub!(/\s*[;#].*/,"")
|
966
|
+
next unless line =~ /\S/
|
967
|
+
case line
|
968
|
+
when /^\s*domain\s+(\S+)/
|
969
|
+
self.domain = $1
|
970
|
+
when /^\s*search\s+(.*)/
|
971
|
+
self.searchlist = $1.split(" ")
|
972
|
+
when /^\s*nameserver\s+(.*)/
|
973
|
+
self.nameservers = $1.split(" ")
|
974
|
+
end
|
1032
975
|
end
|
1033
976
|
end
|
1034
977
|
end
|
@@ -1142,17 +1085,24 @@ module Net
|
|
1142
1085
|
@@udp_socket = socket if @config[:persistent_udp]
|
1143
1086
|
end
|
1144
1087
|
|
1145
|
-
ans =
|
1088
|
+
ans = nil
|
1146
1089
|
response = ""
|
1147
1090
|
@config[:nameservers].each do |ns|
|
1148
|
-
|
1149
|
-
|
1150
|
-
|
1151
|
-
|
1091
|
+
begin
|
1092
|
+
@config[:udp_timeout].timeout do
|
1093
|
+
socket.send(packet_data,0,ns.to_s,@config[:port])
|
1094
|
+
ans = socket.recvfrom(@config[:packet_size])
|
1095
|
+
end
|
1096
|
+
if ans
|
1097
|
+
@logger.info "Received #{ans[0].size} bytes from #{ans[1][2]+":"+ans[1][1].to_s}"
|
1098
|
+
break
|
1099
|
+
end
|
1100
|
+
rescue TimeoutError
|
1101
|
+
@logger.warn "Nameserver #{ns} not responding within UDP timeout, trying next one"
|
1102
|
+
next
|
1152
1103
|
end
|
1153
|
-
response = Net::DNS::Packet.parse(ans[0],ans[1])
|
1154
1104
|
end
|
1155
|
-
return
|
1105
|
+
return Net::DNS::Packet.parse(ans[0],ans[1])
|
1156
1106
|
end
|
1157
1107
|
|
1158
1108
|
def valid?(name)
|
@@ -1170,7 +1120,7 @@ end # module Net
|
|
1170
1120
|
class ResolverArgumentError < ArgumentError # :nodoc:
|
1171
1121
|
end
|
1172
1122
|
|
1173
|
-
|
1123
|
+
module ExtendHash # :nodoc:
|
1174
1124
|
# Returns an hash with all the
|
1175
1125
|
# keys turned into downcase
|
1176
1126
|
#
|
@@ -1186,6 +1136,11 @@ class Hash # :nodoc:
|
|
1186
1136
|
self.replace(hsh)
|
1187
1137
|
end
|
1188
1138
|
end
|
1139
|
+
|
1140
|
+
class Hash # :nodoc:
|
1141
|
+
include ExtendHash
|
1142
|
+
end
|
1143
|
+
|
1189
1144
|
|
1190
1145
|
|
1191
1146
|
|
data/lib/net/dns/rr.rb
CHANGED
@@ -364,7 +364,7 @@ end
|
|
364
364
|
class RRDataError < StandardError # :nodoc:
|
365
365
|
end
|
366
366
|
|
367
|
-
|
367
|
+
module ExtendHash # :nodoc:
|
368
368
|
|
369
369
|
# Performs a sort of group difference
|
370
370
|
# operation on hashes or arrays
|
@@ -384,3 +384,8 @@ class Hash # :nodoc:
|
|
384
384
|
end
|
385
385
|
end
|
386
386
|
end
|
387
|
+
|
388
|
+
class Hash # :nodoc:
|
389
|
+
include ExtendHash
|
390
|
+
end
|
391
|
+
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
|
|
3
3
|
specification_version: 1
|
4
4
|
name: net-dns
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: "0.
|
7
|
-
date: 2007-01-
|
6
|
+
version: "0.2"
|
7
|
+
date: 2007-01-29 00:00:00 +00:00
|
8
8
|
summary: Pure Ruby DNS library
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -39,6 +39,7 @@ files:
|
|
39
39
|
- gemspec
|
40
40
|
- test
|
41
41
|
- Rakefile
|
42
|
+
- InstalledFiles
|
42
43
|
- demo/check_soa.rb
|
43
44
|
- demo/threads.rb
|
44
45
|
- lib/net
|