Node.js: Get client's IP

前端 未结 5 1699
我在风中等你
我在风中等你 2020-12-03 01:13

req.connection.remoteAddress, req.headers[\'x-forwarded-for\'], req.ip, req.ips, what does it all mean?

Is there a straight forward way to simply get the IP address

5条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-03 01:28

    // Get client IP address from request object ----------------------
    getClientAddress = function (req) {
            return (req.headers['x-forwarded-for'] || '').split(',')[0] 
            || req.connection.remoteAddress;
    };
    

提交回复
热议问题