From d3864f2d06e02bbaa965386daf8383bb0992e157 Mon Sep 17 00:00:00 2001 From: Mikaela Suomalainen Date: Mon, 28 Sep 2015 16:45:37 +0300 Subject: [PATCH] add nodejs/myip.js & .gitignore --- .gitignore | 2 ++ nodejs/myip.js | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 .gitignore create mode 100755 nodejs/myip.js diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..19bdd19 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +# I don't like coredumps in my git repos. +*core diff --git a/nodejs/myip.js b/nodejs/myip.js new file mode 100755 index 0000000..c38a737 --- /dev/null +++ b/nodejs/myip.js @@ -0,0 +1,37 @@ +#!/usr/bin/env node + +// Require the dns module +var dns = require('dns'); + +// Set DNS servers to OpenDNS nes +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) { + + // In case of error throw the error message? + 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. + +var servers6 = dns.setServers(["2620:0:ccc::2", "2620:0:ccd::2"]) + +dns.resolve6('myip.opendns.com', function (err, addresses) { + if (err) throw err; + + console.log(addresses[0]); + +}); + +*/