Get Public IP Address for node.js application

后端 未结 4 1040
天命终不由人
天命终不由人 2021-01-15 06:37

Is there any node.js module that can be used to get the public IP address of the client\'s computer making a request? I don\'t mean IPv4 or IPv6, I need the public IP like y

4条回答
  •  鱼传尺愫
    2021-01-15 06:55

    var ip = (req.headers && req.headers['x-forwarded-for'])
             || req.ip 
             || req._remoteAddress 
             || (req.connection && req.connection.remoteAddress);
    

提交回复
热议问题