Node.js: Get client's IP

前端 未结 5 1695
我在风中等你
我在风中等你 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:40

    very simple

    function getClientIP(req){
        return req.headers['x-forwarded-for'] || req.connection.remoteAddress;
    }
    

提交回复
热议问题