1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
-
+
+
+
+
-
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
+
-
-
+
+
+
-
+
-
-
+
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
+
-
-
+
+
+
+
+
+
+
-
-
+
+
+
-
+
-
-
+
+
-
+
+
+
+
-
-
-
+
+
+
-
+
-
-
+
+
|
require "socket"
module AsyncDNS
abstract struct RR
property :name, :class, :type, :ttl
property name : String
property class : DNSClass
property type : RRType
property ttl : UInt32
def initialize(@name : String, @class : DNSClass, @type : RRType,
@ttl : Int32)
@ttl : UInt32)
end
struct A < RR
property :address
property address : Socket::IPAddress
def initialize(name, @address : Socket::IPAddress, ttl)
super(name, DNSClass::IN, RRType::A, ttl)
def initialize(name : String, @address : Socket::IPAddress, ttl : UInt32)
super(name, :in, :a, ttl)
end
end
struct AAAA < RR
property :address
property address : Socket::IPAddress
def initialize(name, @address : Socket::IPAddress, ttl)
super(name, DNSClass::IN, RRType::AAAA, ttl)
def initialize(name : String, @address : Socket::IPAddress, ttl : UInt32)
super(name, :in, :aaaa, ttl)
end
end
struct CNAME < RR
property :alias
property alias : String
def initialize(name, @alias : String, ttl)
super(name, DNSClass::IN, RRType::CNAME, ttl)
def initialize(name : String, @alias : String, ttl : UInt32)
super(name, :in, :cname, ttl)
end
end
struct HINFO < RR
property :cpu, :os
property cpu : String
property os : String
def initialize(name, @cpu : String, @os : String, ttl)
super(name, DNSClass::IN, RRType::HINFO, ttl)
def initialize(name : String, @cpu : String, @os : String, ttl : UInt32)
super(name, :in, :hinfo, ttl)
end
end
struct MX < RR
property preference : UInt16
property :preference, :mx
property mx : String
def initialize(name, @preference : UInt16, @mx : String, ttl)
super(name, DNSClass::IN, RRType::MX, ttl)
def initialize(name : String, @preference : UInt16, @mx : String,
ttl : UInt32)
super(name, :in, :mx, ttl)
end
end
struct NS < RR
property :authority
property authority : String
def initialize(name, @authority : String, ttl)
super(name, DNSClass::IN, RRType::NS, ttl)
def initialize(name : String, @authority : String, ttl : UInt32)
super(name, :in, :ns, ttl)
end
end
struct PTR < RR
property :domain
property domain : String
def initialize(name, @domain : String, ttl)
super(name, DNSClass::IN, RRType::PTR, ttl)
def initialize(name : String, @domain : String, ttl : UInt32)
super(name, :in, :ptr, ttl)
end
end
struct RP < RR
property :mailbox, :domain
property mailbox : String
property domain : String
def initialize(name, @mailbox : String, @domain : String, ttl)
super(name, DNSClass::IN, RRType::RP, ttl)
def initialize(name : String, @mailbox : String, @domain : String,
ttl : UInt32)
super(name, :in, :rp, ttl)
end
end
struct SOA < RR
property primary_ns : String
property responsible : String
property serial : UInt32
property refresh : UInt32
property :primary_ns, :responsible, :serial, :refresh, :retry,
:expire, :min_ttl
property retry : UInt32
property expire : UInt32
property min_ttl : UInt32
def initialize(name, @primary_ns : String, @responsible : String,
def initialize(name : String, @primary_ns : String, @responsible : String,
@serial : UInt32, @refresh : UInt32, @retry : UInt32,
@expire : UInt32, @min_ttl : UInt32)
super(name, DNSClass::IN, RRType::SOA, ttl)
@expire : UInt32, @min_ttl : UInt32, ttl : UInt32)
super(name, :in, :soa, ttl)
end
end
struct SRV < RR
property :prio, :weight, :target, :port
property prio : UInt16
property weight : UInt16
property target : String
property port : UInt16
def initialize(name, @prio : UInt16, @weight : UInt16, @target : String,
@port : UInt16, ttl)
super(name, DNSClass::IN, RRType::SRV, ttl)
def initialize(name : String, @prio : UInt16, @weight : UInt16,
@target : String, @port : UInt16, ttl : UInt32)
super(name, :in, :srv, ttl)
end
end
struct TXT < RR
property :text
property text : Array(String)
def initialize(name, @text : Array(String), ttl)
super(name, DNSClass::IN, RRType::TXT)
def initialize(name : String, @text : Array(String), ttl : UInt32)
super(name, :in, :txt)
end
end
end
end
|