Node.js: Get client's IP

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

    Getting the client IP is pretty straightforward:

     var ip = req.headers['x-forwarded-for'] || 
         req.connection.remoteAddress || 
         req.socket.remoteAddress ||
         req.connection.socket.remoteAddress;
         console.log(ip);
    

提交回复
热议问题