风飘林's Blog
牛博
『NodeJS』简单的本地 DNS 代理脚本var dgram = require("dgram"); const DNSADDRESS = "8.8.8.8"; const DNSPORT = "53"; console.log("DNS Server: " + DNSADDRESS + ":" + DNSPORT); dgram.createSocket("udp4", function (msg, rinfo) { var server = this; var client = dgram.createSocket("udp4"); var address = rinfo.address; var port = rinfo.port; client.send(msg, 0, msg.length, DNSPORT, DNSADDRESS); var tid = 0, buf = null; client.on("message", function (msg, rinfo) { buf = msg; if (tid) clearTimeout(tid); tid = setTimeout(function () { tid = 0; server.send(buf, 0, buf.length, port, address); client.close(); }, 15); }); }).bind(53, "127.0.0.1");欢迎分享,转载请注明来源:内存溢出
评论列表(0条)