scripts/nodejs/myip.js

47 lines
1.4 KiB
JavaScript
Raw Normal View History

2015-09-28 15:45:37 +02:00
#!/usr/bin/env node
// Require the dns module
var dns = require('dns');
2015-09-28 15:54:55 +02:00
// Set DNS servers to OpenDNS IPv4
2015-09-28 15:45:37 +02:00
var servers4 = dns.setServers(["208.67.222.222", "208.67.220.220"])
// Check where myip.opendns.com resolves to and I think this is a function
// that takes arguments err and addresses.
dns.resolve4('myip.opendns.com', function (err, addresses) {
2015-09-28 19:01:52 +02:00
// if err contains a truthy value, an error has occurred
2015-09-28 15:45:37 +02:00
if (err) throw err;
// Print the first thing in array addresses as it has our IPv4
// address.
console.log(addresses[0]);
});
// This code makes node codedump for some reason, maybe it has a bug
// with IPv6 handling or it doesn't like my system not having native
// or not-Teredo IPv6 connectivity.
2015-09-28 15:54:55 +02:00
// node: ../deps/cares/src/ares_destroy.c:102: ares__destroy_servers_state: Assertion `ares__is_list_empty(&server->queries_to_server)' failed.
// zsh: abort (core dumped) ./myip.js
2015-09-28 15:45:37 +02:00
2015-09-28 15:54:55 +02:00
/*
2015-09-28 15:45:37 +02:00
2015-09-28 15:54:55 +02:00
// Set DNS servers to OpenDNS IPv6
2015-09-28 16:02:24 +02:00
var servers6 = dns.setServers(["2620:0:ccc::2", "2620:0:ccd::2"])
2015-09-28 15:45:37 +02:00
2015-09-28 15:54:55 +02:00
// Check where myip.opendns.com resolves to and I think this is a function
// that takes arguments err and addresses.
2015-09-28 16:02:24 +02:00
dns.resolve6('myip.opendns.com', function (err, addresses) {
2015-09-28 15:54:55 +02:00
2015-09-28 19:01:52 +02:00
// if err contains a truthy value, an error has occurred
2015-09-28 15:54:55 +02:00
if (err) throw err;
2015-09-28 15:45:37 +02:00
2015-09-28 15:54:55 +02:00
// Print the first thing in array addresses as it has our IPv4
// address.
console.log(addresses[0]);
});
2015-09-28 15:45:37 +02:00
*/