调用下面方法即可获取

// koa2 中 req 为 ctx.req
const getUserIp = (req) => {
  return req.headers['x-forwarded-for'] ||
    req.connection.remoteAddress ||
    req.socket.remoteAddress ||
    req.connection.socket.remoteAddress;
}

websocket 连接时获取

ws.on('connection', function(wsocket) {
    const ip = wsocket._socket.remoteAddress;
})

 

相关文章:

  • 2022-02-24
  • 2022-02-12
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-11-27
  • 2022-12-23
  • 2022-12-23
  • 2021-12-06
  • 2022-12-23
  • 2022-01-15
  • 2021-06-04
相关资源
相似解决方案