-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdig.wtf.js
159 lines (131 loc) · 4.63 KB
/
dig.wtf.js
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
window.APP = window.APP || {}
class dnsType {
constructor (id, type, desc) {
this.id = id
this.type = type
this.desc = desc
this.answers = []
this.ttl = 0
this.timeout = 1000
this.url = 'https://cloudflare-dns.com/dns-query'
this.resolver = new doh.DohResolver(this.url)
}
resolveName(name) {
this.resolver.query(name, this.type, 'POST', null, this.timeout)
.then(response => {
console.log(JSON.stringify(response))
if (response.answers.length > 0) {
this.ttl = response.answers[0].ttl
_.each(response.answers, a => {
this.answers.push(a.data)
})
}
})
.catch(console.error)
}
test() {
console.log("test")
}
}
const dnsTypes = [
new dnsType(1, 'A', 'IPv4 Address'),
new dnsType(2, 'NS', 'Name Servers'),
//new dnsType(13, 'HINFO', 'Host Information'),
new dnsType(15, 'MX', 'Mail Exchange'),
new dnsType(16, 'TXT', 'Text'),
//new dnsType(17, 'RP', 'Responsible Person'),
//new dnsType(18, 'AFSDB', 'AFS Database Location'),
new dnsType(28, 'AAAA', 'IPv6 Address'),
new dnsType(29, 'LOC', 'Geographical Location'),
//new dnsType(33, 'SRV', 'Service Locator'),
//new dnsType(36, 'KX', 'Key Exchange'),
//new dnsType(37, 'CERT', 'Certificate'),
//new dnsType(42, 'APL', 'Address Prefix List'),
new dnsType(43, 'DS', 'Delegation Signer'),
//new dnsType(44, 'SSHFP', 'SSH Public Key Fingerprint'),
//new dnsType(45, 'IPSECKEY', 'IPsec Key'),
new dnsType(48, 'DNSKEY', 'DNS Key Record'),
//new dnsType(49, 'DHCID', 'DHCP Identifier'),
//new dnsType(52, 'TLSA', 'TLS Certificate Association'),
//new dnsType(53, 'SMIMEA', 'S/MIME Association'),
//new dnsType(55, 'HIP', 'Host Identification Protocol'),
//new dnsType(61, 'OPENPGPKEY', 'OpenPGP Public Key'),
//new dnsType(64, 'SVCB', 'Service Binding'),
new dnsType(65, 'HTTPS', 'HTTPS Binding'),
//new dnsType(108, 'EUI48', 'MAC Address (EUI-48)'),
//new dnsType(109, 'EUI64', 'MAC Address (EUI-64)'),
//new dnsType(256, 'URI', 'Uniform Resource Identifier'),
new dnsType(257, 'CAA', 'Certificate Authority Authorization')
]
APP.DigResultModel = Backbone.Model.extend({})
APP.DigResultsCollection = Backbone.Collection.extend({
model: APP.DigResultModel
})
APP.DigSearchView = Backbone.View.extend({
el: $('#search-form'),
events: {
'submit': 'onSubmit'
},
initialize: function () {
this.hostname = $('input[name=hostname]')
},
onSubmit: function (e) {
e.preventDefault()
Backbone.history.navigate('#/dig/' + this.hostname.val(), false)
}
})
APP.DigResultsView = Backbone.View.extend({
el: $('#results'),
template: _.template($('#dig-template').html()),
initialize: function(options) {
this.collection = options.collection;
_.bindAll(this, 'render');
this.collection.bind('reset', this.render);
this.collection.bind('add', this.render);
this.collection.bind('remove', this.render);
},
render: function () {
var results = { results: [] }
this.collection.forEach(c => {
results.results.push(c.attributes)
})
this.$el.html(this.template(results))
return this
}
})
APP.DigRouter = Backbone.Router.extend({
routes: {
'dig/:host': 'dig'
},
initialize: function () {
this.searchview = new APP.DigSearchView()
this.collection = new APP.DigResultsCollection()
this.resultview = new APP.DigResultsView({ collection: this.collection })
Backbone.history.start()
},
dig: function (name) {
this.collection.reset()
resolver = new doh.DohResolver('https://cloudflare-dns.com/dns-query')
timeout = 1000
resolver.query(name, 'CNAME', 'POST', null, timeout)
.then(response => {
console.log(JSON.stringify(response, null, 4))
if (response.answers.length > 0) {
this.collection.add([{ type: 'CNAME', desc: 'Canonical Name', ttl: response.answers[0].ttl, answers: response.answers }])
} else {
_.each(dnsTypes, v => {
console.log(v)
resolver.query(name, v.type, 'POST', null, timeout)
.then(response => {
console.log(JSON.stringify(response, null, 4))
if (response.answers.length > 0) {
this.collection.add([{ type: v.type, desc: v.desc, ttl: response.answers[0].ttl, answers: response.answers }])
}
})
.catch(console.error)
})
}
})
.catch(console.error)
}
})