check-ip-address
v1.1.3
Published
Returns your remote address from os.networkInterfaces() if available, or false if not.
Downloads
255
Maintainers
Readme
check-ip-address
Test your ip address to see if you're running behind a proxy / firewall or not.
Returns your remote address from os.networkInterfaces()
if available, or false
if not;
Install & Usage
npm install --save check-ip-address
'use strict';
var checkip = require('check-ip-address');
var service = 'https://api.ipify.org'; // default
//var service = 'https://coolaj86.com/services/whatsmyip'; // another option
checkip.getExternalIp(service).then(function (ip) {
console.log("Externally accessible network interface, if any:", ip);
// false - no internal interfaces match the external address
// '107.23.87.1' - example ip address that is publicly accessible
});
Actual Use Case
'use strict';
var http = require('http')
, port = process.argv[2] || 3000
, checkip = require('check-ip-address')
, server = http.createServer()
;
checkip.getExternalIp().then(function (ip) {
var host = ip || 'localhost'
, fqdn = ip || 'local.foobar3000.com'
;
function app(req, res) {
// this 'app' would be a real server such as:
// require('../server').create(server).then(function (app) { ... });
res.end(fqdn);
}
server.on('request', app);
server.listen(port, function() {
console.log('\n', 'Listening on http://' + host + ':' + port, '\n');
if (host !== fqdn) {
console.log('Test this link in your browser also:');
console.log(' http://' + fqdn + ':' + port);
}
console.log('');
});
});