-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
dns-to-https-proxy.js
executable file
·66 lines (56 loc) · 1.68 KB
/
dns-to-https-proxy.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
#!/usr/bin/env node
const dgram = require('dgram')
const got = require('got')
const dnsPacket = require('dns-packet')
const port = process.env["DNS_PORT"] || 53
//https://cloudflare-dns.com/dns-query"
const url = process.env["DNS_URL"]
|| "https://dns.google/dns-query"
const allow_selfSigned = (process.env["DNS_INSECURE"] == 1)
//pinning to IPv4 as server was replying on IPv6 when request came in on IPv4
const server = dgram.createSocket('udp4')
server.on('listening', function(){
console.log("listening")
})
server.on('message', async function(msg, remote){
var packet = dnsPacket.decode(msg)
var id = packet.id
const options = {
url: url,
body: msg,
https: {
rejectUnauthorized: allow_selfSigned ? false : true
},
headers: {
'Accept': 'application/dns-message',
'Content-Type': 'application/dns-message'
},
responseType: 'buffer'
}
const resp = await got.post(options).buffer()
const respPacket = dnsPacket.decode(resp)
respPacket.id = id
server.send(dnsPacket.encode(respPacket), remote.port)
// var options = {
// url: url,
// method: 'POST',
// body: msg,
// encoding: null,
// rejectUnauthorized: allow_selfSigned ? false : true,
// headers: {
// 'Accept': 'application/dns-message',
// 'Content-Type': 'application/dns-message'
// }
// }
// request(options, function(err, resp, body){
// if (!err && resp.statusCode == 200) {
// var respPacket = dnsPacket.decode(body)
// respPacket.id = id
// // console.log(respPacket);
// server.send(dnsPacket.encode(respPacket),remote.port)
// } else {
// console.log(err)
// }
// })
})
server.bind(port)