nodejs获取ip

let getClientIp = function (req) {

    return req.headers['x-forwarded-for'] ||

        req.connection.remoteAddress ||

        req.socket.remoteAddress ||

        req.connection.socket.remoteAddress || '';

};

let ip = getClientIp(req).match(/\d+.\d+.\d+.\d+/);

console.log(ip);

ip = ip ? ip.join('.') : null;

console.log(ip);

你可能感兴趣的:(nodejs获取ip)