如何获取服务器的地理位置,如何获取Restify服务器的确切IP地址进行监听?
var restify = require('restify');
var server = restify.createServer();
server.get('/echo/:name', function (req, res, next) {
res.send({name: req.params.name});
next();
});
server.listen(8080, function() {
console.log('%s listening at %s', server.name, server.url);
});
運行了該服務器節點:
$ node echo.js
restify listening at http://0.0.0.0:8080
它顯示0.0.0.0這是不對的。
任何人都可以如何控制臺登錄服務器的確切IP時,它打開?
感謝
更新: 上執行下面的代碼我得到下面提到的輸出,這又是制造困難,這IP選?
rest_server.listen(config.appPort, function() {
var adrs = require('os').networkInterfaces();
console.log(adrs);
console.log('%s listening at %s', rest_server.name, rest_server.url);
});
輸出:
{ 'Local Area Connection': [ { address: '192.168.3.60', family: 'IPv4', internal
: false } ],
'Loopback Pseudo-Interface 1':
[ { address: '::1', family: 'IPv6', internal: true },
{ address: '127.0.0.1', family: 'IPv4', internal: true } ],
'isatap.TEST.ORG':
[ { address: 'fe80::5efe:c0a8:33c',
family: 'IPv6',
internal: false } ] }
restify listening at http://0.0.0.0:8080
+0
在這種情況下,你應該選擇'192.168.3.60',因為它不是內部*和* IPv4的。 –
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的如何获取服务器的地理位置,如何获取Restify服务器的确切IP地址进行监听?的全部內容,希望文章能夠幫你解決所遇到的問題。