Nodejs获取客户端IP

发布时间:2018-11-16编辑:佚名阅读(882)

//获取url请求客户端ip
var get_client_ip = function(req) {
    var ip = req.headers['x-forwarded-for'] ||
        req.ip ||
        req.connection.remoteAddress ||
        req.socket.remoteAddress ||
        req.connection.socket.remoteAddress || '';
    if(ip.split(',').length>0){
        ip = ip.split(',')[0]
    }
    return ip;
};


  关键字:Nodejs获取客户端IP


鼓掌

0

正能量

0

0

呵呵

0


评论区