如何确定节点中的用户IP地址

如何确定控制器中给定请求的IP地址?例如(快递):

app.post('/get/ip/address', function (req, res) {
    // need access to IP address here
})
米亚宝儿2020/03/18 16:51:12

Had the same problem...im also new at javascript but i solved this with req.connection.remoteAddress; that gave me th IP address (but in ipv6 format ::ffff.192.168.0.101 ) and then .slice to remove the 7 first digits.

var ip = req.connection.remoteAddress;

if (ip.length < 15) 
{   
   ip = ip;
}
else
{
   var nyIP = ip.slice(7);
   ip = nyIP;
}
理查德乐2020/03/18 16:51:12

如果使用快递...

req.ip

我一直在寻找,然后就像等待,我正在使用快递。咄。