mirror of https://github.com/nodejs/node.git
Simplify the DNS usage example.
parent
41d89f611f
commit
4db8bb9375
|
@ -1010,36 +1010,32 @@ necessary in case of errors (parse error or so).
|
||||||
|
|
||||||
=== DNS
|
=== DNS
|
||||||
|
|
||||||
Here is an example of which reads domains from the command line, resolves
|
Here is an example of which resolves +"www.google.com"+ then reverse
|
||||||
them, then reverse resolves the IP addresses returned.
|
resolves the IP addresses which are returned.
|
||||||
|
|
||||||
-------------------------------------------------------------------------
|
-------------------------------------------------------------------------
|
||||||
for (var i = 2; i < ARGV.length; i++) {
|
var resolution = node.dns.resolve4("www.google.com");
|
||||||
var name = ARGV[i]
|
|
||||||
puts("looking up " + name);
|
|
||||||
var resolution = node.dns.resolve4(name);
|
|
||||||
|
|
||||||
resolution.addCallback(function (addresses, ttl, cname) {
|
resolution.addCallback(function (addresses, ttl, cname) {
|
||||||
puts("addresses: " + JSON.stringify(addresses));
|
puts("addresses: " + JSON.stringify(addresses));
|
||||||
puts("ttl: " + JSON.stringify(ttl));
|
puts("ttl: " + JSON.stringify(ttl));
|
||||||
puts("cname: " + JSON.stringify(cname));
|
puts("cname: " + JSON.stringify(cname));
|
||||||
|
|
||||||
for (var i = 0; i < addresses.length; i++) {
|
for (var i = 0; i < addresses.length; i++) {
|
||||||
var a = addresses[i];
|
var a = addresses[i];
|
||||||
var reversing = node.dns.reverse(a);
|
var reversing = node.dns.reverse(a);
|
||||||
reversing.addCallback( function (domains, ttl, cname) {
|
reversing.addCallback( function (domains, ttl, cname) {
|
||||||
puts("reverse for " + a + ": " + JSON.stringify(domains));
|
puts("reverse for " + a + ": " + JSON.stringify(domains));
|
||||||
});
|
});
|
||||||
reversing.addErrback( function (code, msg) {
|
reversing.addErrback( function (code, msg) {
|
||||||
puts("reverse for " + a + " failed: " + msg);
|
puts("reverse for " + a + " failed: " + msg);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
resolution.addErrback(function (code, msg) {
|
resolution.addErrback(function (code, msg) {
|
||||||
puts("error: " + msg);
|
puts("error: " + msg);
|
||||||
});
|
});
|
||||||
}
|
|
||||||
-------------------------------------------------------------------------
|
-------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue