node 获取用户ip地址
在node层获取访问用户的ip地址
var express = require('express');
var app = express()
app.get('/', function(req, res){
console.log( getClientIp(req))
})
function getClientIp(req) {
return req.headers['x-forwarded-for'] ||
req.connection.remoteAddress ||
req.socket.remoteAddress ||
req.connection.socket.remoteAddress;
};
app.listen(3000)