koa2获取用户ip
调用下面方法即可获取
// 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;
})
如果你发现你的学习缺乏动力了,那么你只需要在这里调出这篇博客的一大堆毛病并对作者嗤之以鼻,不断抨击作者直到作者的修改让你满意为止,那么你的动力就自然而来了!

浙公网安备 33010602011771号