net-dns 0.6.1 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +8 -6
- data/.travis.yml +14 -0
- data/CHANGELOG.md +79 -0
- data/Gemfile +4 -0
- data/Rakefile +56 -66
- data/demo/check_soa.rb +1 -1
- data/demo/threads.rb +1 -1
- data/lib/net/dns.rb +24 -22
- data/lib/net/dns/header.rb +77 -103
- data/lib/net/dns/{names/names.rb → names.rb} +19 -20
- data/lib/net/dns/packet.rb +231 -256
- data/lib/net/dns/question.rb +11 -40
- data/lib/net/dns/resolver.rb +248 -250
- data/lib/net/dns/resolver/socks.rb +6 -6
- data/lib/net/dns/resolver/timeouts.rb +1 -1
- data/lib/net/dns/rr.rb +112 -117
- data/lib/net/dns/rr/a.rb +98 -89
- data/lib/net/dns/rr/aaaa.rb +84 -68
- data/lib/net/dns/rr/classes.rb +91 -106
- data/lib/net/dns/rr/cname.rb +64 -45
- data/lib/net/dns/rr/hinfo.rb +90 -50
- data/lib/net/dns/rr/mr.rb +61 -44
- data/lib/net/dns/rr/mx.rb +73 -48
- data/lib/net/dns/rr/ns.rb +60 -46
- data/lib/net/dns/rr/null.rb +11 -12
- data/lib/net/dns/rr/ptr.rb +47 -34
- data/lib/net/dns/rr/soa.rb +5 -6
- data/lib/net/dns/rr/srv.rb +1 -4
- data/lib/net/dns/rr/txt.rb +14 -14
- data/lib/net/dns/rr/types.rb +13 -13
- data/lib/net/dns/version.rb +8 -14
- data/net-dns.gemspec +35 -0
- data/setup.rb +3 -2
- data/test/header_test.rb +18 -18
- data/test/names_test.rb +21 -0
- data/test/packet_test.rb +38 -31
- data/test/question_test.rb +23 -24
- data/test/resolver/timeouts_test.rb +13 -13
- data/test/resolver_test.rb +28 -20
- data/test/rr/a_test.rb +70 -23
- data/test/rr/aaaa_test.rb +109 -0
- data/test/rr/classes_test.rb +61 -49
- data/test/rr/cname_test.rb +97 -0
- data/test/rr/hinfo_test.rb +117 -0
- data/test/rr/mr_test.rb +105 -0
- data/test/rr/mx_test.rb +112 -0
- data/test/rr/ns_test.rb +34 -12
- data/test/rr/types_test.rb +4 -4
- data/test/rr_test.rb +1 -1
- metadata +77 -52
- data/AUTHORS.rdoc +0 -7
- data/CHANGELOG.rdoc +0 -46
- data/VERSION.yml +0 -5
data/lib/net/dns/rr/hinfo.rb
CHANGED
@@ -1,68 +1,108 @@
|
|
1
|
-
module Net
|
1
|
+
module Net # :nodoc:
|
2
2
|
module DNS
|
3
3
|
class RR
|
4
|
-
|
5
|
-
|
6
|
-
#
|
7
|
-
|
4
|
+
|
5
|
+
#
|
6
|
+
# = System Information Record (HINFO)
|
7
|
+
#
|
8
|
+
# Class for DNS HINFO resource records.
|
9
|
+
#
|
10
|
+
# Allows definition of the Hardware type and Operating System (OS) in use at a host.
|
11
|
+
# For security reasons these records are rarely used on public servers.
|
12
|
+
# If a space exists in the field it must be enclosed in quotes.
|
13
|
+
# Single space between CPU and OS parameters.
|
14
|
+
#
|
8
15
|
class HINFO < RR
|
9
|
-
attr_reader :cpu, :os
|
10
16
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
else
|
17
|
-
raise ArgumentError, "HINFO section not valid: #{str.inspect}"
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def build_pack
|
22
|
-
@hinfo_pack = [@cpu.size].pack("C") + @cpu
|
23
|
-
@hinfo_pack += [@os.size].pack("C") + @os
|
24
|
-
@rdlength = @hinfo_pack.size
|
17
|
+
# Gets the CPU value.
|
18
|
+
#
|
19
|
+
# Returns a String.
|
20
|
+
def cpu
|
21
|
+
@cpu
|
25
22
|
end
|
26
23
|
|
27
|
-
|
28
|
-
|
24
|
+
# Gets the OS value.
|
25
|
+
#
|
26
|
+
# Returns a String.
|
27
|
+
def os
|
28
|
+
@os
|
29
29
|
end
|
30
30
|
|
31
|
-
|
32
|
-
|
31
|
+
# Gets the standardized value for this record,
|
32
|
+
# represented by the value of <tt>cpu</tt> and <tt>os</tt>.
|
33
|
+
#
|
34
|
+
# Returns a String.
|
35
|
+
def value
|
36
|
+
%Q{"#{cpu}" "#{os}"}
|
33
37
|
end
|
34
38
|
|
35
|
-
def subclass_new_from_hash(args)
|
36
|
-
if args.has_key? :cpu and args.has_key? :os
|
37
|
-
@cpu = args[:cpu]
|
38
|
-
@os = args[:os]
|
39
|
-
else
|
40
|
-
raise ArgumentError, ":cpu and :os fields are mandatory but missing"
|
41
|
-
end
|
42
|
-
end
|
43
39
|
|
44
|
-
|
45
|
-
|
40
|
+
# Gets a list of all the attributes for this record.
|
41
|
+
#
|
42
|
+
# Returns an Array of values.
|
43
|
+
def to_a
|
44
|
+
[nil, nil, cls.to_s, type.to_s, value]
|
46
45
|
end
|
47
46
|
|
48
|
-
|
49
|
-
len = data.unpack("@#{offset} C")[0]
|
50
|
-
@cpu = data[offset+1..offset+1+len]
|
51
|
-
offset += len+1
|
52
|
-
len = @data.unpack("@#{offset} C")[0]
|
53
|
-
@os = data[offset+1..offset+1+len]
|
54
|
-
return offset += len+1
|
55
|
-
end
|
56
|
-
|
47
|
+
|
57
48
|
private
|
58
|
-
|
49
|
+
|
50
|
+
def subclass_new_from_hash(options)
|
51
|
+
if options.has_key?(:cpu) && options.has_key?(:os)
|
52
|
+
@cpu = options[:cpu]
|
53
|
+
@os = options[:os]
|
54
|
+
else
|
55
|
+
raise ArgumentError, ":cpu and :os fields are mandatory"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def subclass_new_from_string(str)
|
60
|
+
@cpu, @os = check_hinfo(str)
|
61
|
+
end
|
62
|
+
|
63
|
+
def subclass_new_from_binary(data, offset)
|
64
|
+
len = data.unpack("@#{offset} C").first
|
65
|
+
offset += 1
|
66
|
+
@cpu = data[offset..(offset + len)]
|
67
|
+
offset += len
|
68
|
+
|
69
|
+
len = data.unpack("@#{offset} C").first
|
70
|
+
offset += 1
|
71
|
+
@os = data[offset..(offset + len)]
|
72
|
+
offset += len
|
73
|
+
end
|
74
|
+
|
75
|
+
|
59
76
|
def set_type
|
60
77
|
@type = Net::DNS::RR::Types.new("HINFO")
|
61
78
|
end
|
62
|
-
|
63
|
-
end # class HINFO
|
64
|
-
|
65
|
-
end # class RR
|
66
|
-
end # module DNS
|
67
|
-
end # module Net
|
68
79
|
|
80
|
+
def get_inspect
|
81
|
+
value
|
82
|
+
end
|
83
|
+
|
84
|
+
|
85
|
+
def check_hinfo(input)
|
86
|
+
if input.to_s.strip =~ /^(?:["']?(.*?)["']?)\s+(?:["']?(.*?)["']?)$/
|
87
|
+
[$1, $2]
|
88
|
+
else
|
89
|
+
raise ArgumentError, "Invalid HINFO Section `#{input}'"
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def build_pack
|
94
|
+
@hinfo_pack = ""
|
95
|
+
@hinfo_pack += [cpu.size].pack("C") + cpu
|
96
|
+
@hinfo_pack += [os.size ].pack("C") + os
|
97
|
+
@rdlength = @hinfo_pack.size
|
98
|
+
end
|
99
|
+
|
100
|
+
def get_data
|
101
|
+
@hinfo_pack
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
data/lib/net/dns/rr/mr.rb
CHANGED
@@ -1,62 +1,79 @@
|
|
1
|
-
module Net
|
1
|
+
module Net # :nodoc:
|
2
2
|
module DNS
|
3
3
|
|
4
4
|
class RR
|
5
|
-
|
6
|
-
|
7
|
-
#
|
8
|
-
|
5
|
+
|
6
|
+
#
|
7
|
+
# = Mail Rename Record (MR)
|
8
|
+
#
|
9
|
+
# Class for DNS MR resource records.
|
10
|
+
#
|
9
11
|
class MR < RR
|
10
|
-
attr_reader :newname
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
end
|
18
|
-
name
|
13
|
+
# Gets the newname value.
|
14
|
+
#
|
15
|
+
# Returns a String.
|
16
|
+
def newname
|
17
|
+
@newname
|
19
18
|
end
|
20
19
|
|
21
|
-
|
22
|
-
|
23
|
-
|
20
|
+
# Gets the standardized value for this record,
|
21
|
+
# represented by the value of <tt>newname</tt>.
|
22
|
+
#
|
23
|
+
# Returns a String.
|
24
|
+
def value
|
25
|
+
newname.to_s
|
24
26
|
end
|
25
27
|
|
26
|
-
def get_data
|
27
|
-
@newname_pack
|
28
|
-
end
|
29
28
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
29
|
+
private
|
30
|
+
|
31
|
+
def subclass_new_from_hash(options)
|
32
|
+
if options.has_key?(:newname)
|
33
|
+
@newname = check_name(options[:newname])
|
34
|
+
else
|
35
|
+
raise ArgumentError, ":newname field is mandatory"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def subclass_new_from_string(str)
|
40
|
+
@newname = check_name(str)
|
41
|
+
end
|
42
|
+
|
43
|
+
def subclass_new_from_binary(data, offset)
|
44
|
+
@newname = dn_expand(data,offset)
|
45
|
+
offset
|
39
46
|
end
|
40
|
-
end
|
41
47
|
|
42
|
-
def subclass_new_from_string(str)
|
43
|
-
@newname = check_name(str)
|
44
|
-
end
|
45
48
|
|
46
|
-
def subclass_new_from_array(data,offset)
|
47
|
-
@newname = dn_expand(data,offset)
|
48
|
-
return offset
|
49
|
-
end
|
50
|
-
|
51
|
-
private
|
52
|
-
|
53
49
|
def set_type
|
54
50
|
@type = Net::DNS::RR::Types.new("MR")
|
55
51
|
end
|
56
|
-
|
57
|
-
end # class MR
|
58
52
|
|
59
|
-
|
60
|
-
|
61
|
-
end
|
53
|
+
def get_inspect
|
54
|
+
value
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
def check_name(input)
|
59
|
+
name = input.to_s
|
60
|
+
unless name =~ /(\w\.?)+\s*$/
|
61
|
+
raise ArgumentError, "Invalid Domain Name `#{name}'"
|
62
|
+
end
|
63
|
+
name
|
64
|
+
end
|
65
|
+
|
66
|
+
def build_pack
|
67
|
+
@newname_pack = pack_name(@newname)
|
68
|
+
@rdlength = @newname_pack.size
|
69
|
+
end
|
70
|
+
|
71
|
+
def get_data
|
72
|
+
@newname_pack
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
62
76
|
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
data/lib/net/dns/rr/mx.rb
CHANGED
@@ -1,67 +1,92 @@
|
|
1
|
-
module Net
|
1
|
+
module Net # :nodoc:
|
2
2
|
module DNS
|
3
3
|
class RR
|
4
|
-
|
5
|
-
|
6
|
-
#
|
7
|
-
|
4
|
+
|
5
|
+
#
|
6
|
+
# = Mail Exchange Record (MX)
|
7
|
+
#
|
8
|
+
# Class for DNS MX resource records.
|
9
|
+
#
|
10
|
+
# A MX record specifies the name and relative preference of mail servers
|
11
|
+
# (mail exchangers in the DNS jargon) for the zone.
|
12
|
+
# The MX RR is used by SMTP (Mail) Agents to route mail for the domain.
|
13
|
+
#
|
8
14
|
class MX < RR
|
9
|
-
attr_reader :preference, :exchange
|
10
15
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
else
|
17
|
-
raise ArgumentError, "MX section not valid"
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def build_pack
|
22
|
-
@mx_pack = [@preference].pack("n") + pack_name(@exchange)
|
23
|
-
@rdlength = @mx_pack.size
|
16
|
+
# Gets the preference value.
|
17
|
+
#
|
18
|
+
# Returns an Integer.
|
19
|
+
def preference
|
20
|
+
@preference
|
24
21
|
end
|
25
22
|
|
26
|
-
|
27
|
-
|
23
|
+
# Gets the exchange value.
|
24
|
+
#
|
25
|
+
# Returns a String.
|
26
|
+
def exchange
|
27
|
+
@exchange
|
28
28
|
end
|
29
29
|
|
30
|
-
|
31
|
-
|
30
|
+
# Gets the standardized value for this record,
|
31
|
+
# represented by the value of <tt>preference</tt> and <tt>exchange</tt>.
|
32
|
+
#
|
33
|
+
# Returns a String.
|
34
|
+
def value
|
35
|
+
"#{preference} #{exchange}"
|
32
36
|
end
|
33
37
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def subclass_new_from_hash(options)
|
42
|
+
if options.has_key?(:preference) && options.has_key?(:exchange)
|
43
|
+
@preference = options[:preference].to_i
|
44
|
+
@exchange = options[:exchange]
|
45
|
+
else
|
46
|
+
raise ArgumentError, ":preference and :exchange fields are mandatory"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def subclass_new_from_string(str)
|
51
|
+
@preference, @exchange = check_mx(str)
|
52
|
+
end
|
53
|
+
|
54
|
+
def subclass_new_from_binary(data, offset)
|
55
|
+
@preference = data.unpack("@#{offset} n")[0]
|
56
|
+
offset += 2
|
57
|
+
@exchange, offset = dn_expand(data, offset)
|
58
|
+
offset
|
40
59
|
end
|
41
|
-
end
|
42
60
|
|
43
|
-
def subclass_new_from_string(str)
|
44
|
-
@preference,@exchange = check_mx(str)
|
45
|
-
end
|
46
61
|
|
47
|
-
def subclass_new_from_binary(data,offset)
|
48
|
-
@preference = data.unpack("@#{offset} n")[0]
|
49
|
-
offset += 2
|
50
|
-
@exchange,offset = dn_expand(data,offset)
|
51
|
-
return offset
|
52
|
-
end
|
53
|
-
|
54
|
-
private
|
55
|
-
|
56
62
|
def set_type
|
57
63
|
@type = Net::DNS::RR::Types.new("MX")
|
58
64
|
end
|
59
|
-
|
60
|
-
end # class MX
|
61
|
-
|
62
|
-
end # class RR
|
63
|
-
end # module DNS
|
64
|
-
end # module Net
|
65
65
|
|
66
|
+
def get_inspect
|
67
|
+
value
|
68
|
+
end
|
69
|
+
|
70
|
+
|
71
|
+
def check_mx(input)
|
72
|
+
str = input.to_s
|
73
|
+
unless str.strip =~ /^(\d+)\s+(\S+)$/
|
74
|
+
raise ArgumentError, "Invalid MX section `#{str}'"
|
75
|
+
end
|
76
|
+
[$1.to_i, $2]
|
77
|
+
end
|
78
|
+
|
79
|
+
def build_pack
|
80
|
+
@mx_pack = [@preference].pack("n") + pack_name(@exchange)
|
81
|
+
@rdlength = @mx_pack.size
|
82
|
+
end
|
83
|
+
|
84
|
+
def get_data
|
85
|
+
@mx_pack
|
86
|
+
end
|
66
87
|
|
88
|
+
end
|
67
89
|
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
data/lib/net/dns/rr/ns.rb
CHANGED
@@ -1,64 +1,78 @@
|
|
1
|
-
module Net
|
1
|
+
module Net # :nodoc:
|
2
2
|
module DNS
|
3
|
-
|
4
3
|
class RR
|
5
|
-
|
6
|
-
|
7
|
-
#
|
8
|
-
|
4
|
+
|
5
|
+
#
|
6
|
+
# = Name Server Record (NS)
|
7
|
+
#
|
8
|
+
# Class for DNS NS resource records.
|
9
|
+
#
|
9
10
|
class NS < RR
|
10
|
-
attr_reader :nsdname
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
end
|
18
|
-
name
|
12
|
+
# Gets the name server value.
|
13
|
+
#
|
14
|
+
# Returns a String.
|
15
|
+
def nsdname
|
16
|
+
@nsdname
|
19
17
|
end
|
20
18
|
|
21
|
-
|
22
|
-
|
23
|
-
|
19
|
+
# Gets the standardized value for this record,
|
20
|
+
# represented by the value of <tt>nsdname</tt>.
|
21
|
+
#
|
22
|
+
# Returns a String.
|
23
|
+
def value
|
24
|
+
nsdname.to_s
|
24
25
|
end
|
25
26
|
|
26
|
-
def get_data
|
27
|
-
@nsdname_pack
|
28
|
-
end
|
29
27
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
28
|
+
private
|
29
|
+
|
30
|
+
def subclass_new_from_hash(options)
|
31
|
+
if options.has_key?(:nsdname)
|
32
|
+
@nsdname = check_name(options[:nsdname])
|
33
|
+
else
|
34
|
+
raise ArgumentError, ":nsdname field is mandatory"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def subclass_new_from_string(str)
|
39
|
+
@nsdname = check_name(str)
|
40
|
+
end
|
41
|
+
|
42
|
+
def subclass_new_from_binary(data, offset)
|
43
|
+
@nsdname, offset = dn_expand(data, offset)
|
44
|
+
offset
|
39
45
|
end
|
40
|
-
end
|
41
46
|
|
42
|
-
def subclass_new_from_string(str)
|
43
|
-
@nsdname = check_name(str)
|
44
|
-
end
|
45
47
|
|
46
|
-
def subclass_new_from_binary(data,offset)
|
47
|
-
@nsdname,offset = dn_expand(data,offset)
|
48
|
-
return offset
|
49
|
-
end
|
50
|
-
|
51
|
-
private
|
52
|
-
|
53
48
|
def set_type
|
54
49
|
@type = Net::DNS::RR::Types.new("NS")
|
55
50
|
end
|
56
|
-
|
57
|
-
end # class NS
|
58
|
-
|
59
|
-
end # class RR
|
60
|
-
end # module DNS
|
61
|
-
end # module Net
|
62
51
|
|
52
|
+
def get_inspect
|
53
|
+
value
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
def check_name(input)
|
58
|
+
name = input.to_s
|
59
|
+
unless name =~ /(\w\.?)+\s*$/ and name =~ /[a-zA-Z]/
|
60
|
+
raise ArgumentError, "Invalid Name Server `#{name}'"
|
61
|
+
end
|
62
|
+
name
|
63
|
+
end
|
64
|
+
|
65
|
+
def build_pack
|
66
|
+
@nsdname_pack = pack_name(@nsdname)
|
67
|
+
@rdlength = @nsdname_pack.size
|
68
|
+
end
|
69
|
+
|
70
|
+
def get_data
|
71
|
+
@nsdname_pack
|
72
|
+
end
|
63
73
|
|
74
|
+
end
|
64
75
|
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|