Permalink
Browse files

second commit

  • Loading branch information...
1 parent 84a0201 commit b5b73b46ee3628b0fec79e60b886506ab2d44990 tomas committed Aug 24, 2010
Showing with 2,292 additions and 0 deletions.
  1. +44 −0 examples/authorative.js
  2. +18 −0 examples/proxy.js
  3. +33 −0 examples/zonewalk.js
  4. +2,197 −0 lib/ndns.js
View
@@ -0,0 +1,44 @@
+var sys = require('sys'), puts = sys.puts;
+var dgram = require('dgram');
+var ndns = require('../lib/ndns');
+var server = ndns.createServer('udp4');
+var client = ndns.createClient('udp4');
+
+var BIND_PORT = 53;
+
+server.on("request", function(req, res) {
+ res.setHeader(req.header);
+
+ for (var i = 0; i < req.q.length; i++)
+ res.addQuestion(req.q[i]);
+
+ if (req.q.length > 0) {
+ var name = req.q[0].name;
+ if (name == ".")
+ name = "";
+ res.header.qr = 1;
+ res.header.ra = 1;
+ res.header.rd = 0;
+ res.header.ancount = 3;
+ res.header.nscount = 4;
+ res.header.arcount = 5;
+ res.addRR(name, 1, "IN", "SOA",
+ "hostmaster." + name,
+ "hostmaster." + name,
+ 1, 2, 3, 4, 5);
+ res.addRR(name, 2, "IN", "TXT", "Hello World");
+ res.addRR(name, 3, "IN", "MX", 10, "mail." + name);
+ res.addRR(name, 4, "IN", "NS", "ns1." + name);
+ res.addRR(name, 5, "IN", "NS", "ns2." + name);
+ res.addRR(name, 6, "IN", "NS", "ns3." + name);
+ res.addRR(name, 7, "IN", "NS", "ns4." + name);
+ res.addRR("mail." + name, 8, "IN", "A", "127.0.0.1");
+ res.addRR("ns1." + name, 9, "IN", "A", "127.0.0.1");
+ res.addRR("ns2." + name, 10, "IN", "A", "127.0.0.2");
+ res.addRR("ns3." + name, 11, "IN", "A", "127.0.0.3");
+ res.addRR("ns4." + name, 12, "IN", "A", "127.0.0.4");
+ }
+ res.send();
+});
+
+server.bind(BIND_PORT);
View
@@ -0,0 +1,18 @@
+var ndns = require('../lib/ndns');
+var server = ndns.createServer('udp4');
+var client = ndns.createClient('udp4');
+
+var LOCAL_PORT = 53;
+var REMOTE_HOST = "4.2.2.1"
+var REMOTE_PORT = 53;
+
+server.on("request", function(req, res) {
+ var c_req = client.request(REMOTE_PORT, REMOTE_HOST);
+ c_req.on("response", function (c_res) {
+ res.send(c_res);
+ });
+ c_req.send(req);
+});
+
+server.bind(LOCAL_PORT);
+client.bind();
View
@@ -0,0 +1,33 @@
+var sys = require('sys'), puts = sys.puts;
+var ndns = require('../lib/ndns');
+var resolver = ndns.createClient('udp4');
+
+function walk (a_root_servers_net, domain) {
+ puts(domain);
+ var req = resolver.request(53, a_root_servers_net);
+
+ req.setHeader({
+ id: 1992,
+ rd: 1,
+ qdcount: 1});
+ req.addQuestion (domain, "NSEC", "IN");
+ req.send();
+
+ req.on("response", function (res) {
+ var rr;
+ for (var i = 0; i < res.rr.length; i++) {
+ rr = res.rr[i];
+ if (rr.typeName == "NSEC") {
+ walk(a_root_servers_net, rr.rdata.next_domain_name);
+ break;
+ }
+ }
+ });
+}
+
+require('dns').resolve4("A.ROOT-SERVERS.NET", function (err, addrs) {
+ if (err) throw err;
+ if (addrs.length > 0)
+ walk(addrs[0], ".");
+});
+
Oops, something went wrong.

0 comments on commit b5b73b4

Please sign in to comment.