/
resolver.html
69 lines (65 loc) · 2.02 KB
/
resolver.html
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
<!-- Example HTML file using dohjs -->
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>dohjs example</title>
<!-- Load dohjs -->
<script src="https://cdn.jsdelivr.net/npm/dohjs@latest/dist/doh.js"></script>
</head>
<body>
<table>
<tr>
<th>Field name</th>
<th>Value</th>
</tr>
<tr>
<td>URL</td>
<td><input type="text" id="url" value="https://dns.google/dns-query"></td>
</tr>
<tr>
<td>Query name</td>
<td><input type="text" id="qname" value="example.com"></td>
</tr>
<tr>
<td>Query type</td>
<td><input type="text" id="qtype" value="A"></td>
</tr>
<tr>
<td>Request method</td>
<td><input type="text" id="method" value="GET"></td>
</tr>
<tr>
<td>Timeout (ms)</td>
<td><input type="number" id="timeout" value="1000"></td>
</tr>
</table>
<input type="button" id="send-query" value="Send query">
<pre id="output"></pre>
<!-- Here's an example script where we use dohjs -->
<script>
document.addEventListener('DOMContentLoaded', function (e) {
document.getElementById('send-query').addEventListener('click', function (e) {
const qname = document.getElementById('qname').value || '.';
const qtype = document.getElementById('qtype').value || 'A';
const method = document.getElementById('method').value || 'POST';
const timeout = parseInt(document.getElementById('timeout').value) || 1000;
const url = document.getElementById('url').value;
if (!url) {
alert('You forgot to provide a URL!');
return;
}
const resolver = new doh.DohResolver(url);
resolver.query(qname, qtype, method, null, timeout)
.then(response => {
document.getElementById('output').innerHTML = JSON.stringify(response, null, 4);
})
.catch(console.error);
});
});
</script>
</body>
</html>