在 Meteor 中创建用户时获取客户端的 ip [英] Get client's ip at user creation in Meteor

查看:51
本文介绍了在 Meteor 中创建用户时获取客户端的 ip的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 Meteor 中创建自定义登录/注册,因为我需要检查电子邮件格式,更重要的是在注册表单中添加一个 recaptcha,这需要客户的 ip.

I'm creating a custom sign-in/sign-up in Meteor because I need to check the email format and more importantly to add a recaptcha in the sign-up form, which requires the client's ip.

所以我打算在Accounts.validateNewUser中验证验证码,但我不知道如何在此处获取客户端的IP.我阅读了关于如何做的answer那,但这不是我想要的地方.我检查了 Meteor.default_server.sessions,其中包含服务器上的所有会话/套接字.它们包含有关所有套接字的标头、ips 的信息.每一个都有有趣的东西,比如:

So I plan to verify the captcha in Accounts.validateNewUser, but I cant figure out how to get the client's ip here. I read an answer on how to do that, but it's not where I want to. I checked Meteor.default_server.sessions which contains all the sessions/sockets on the server. They contain information about headers, ips of all sockets. Each one has interesting stuff like:

pathname: "/sockjs/375/ibmrlwb2/xhr"
prefix: "/sockjs"
protocol: "xhr-polling"
remoteAddress: "127.0.0.1"
remotePort: 42009

但是不知道当前是哪个socket,就无法确定当前请求的ip是哪个.

But without knowing which socket is the current one, I cannot determine which ip of the current request is.

我如何知道服务器的当前请求 url?有了它,我可以检查服务器上的所有套接字以推断客户端的 IP.

How can I know the current request url to the server? With that I can check with all the sockets on the server to infer the client's ip.

或者只是简单地如何在服务器上获取客户端的 ip?

Or just simply how can I get the client's ip on the server?

推荐答案

我是 user-status 另一个答案中提到的包.

I'm the maintainer of the user-status package mentioned in the other answer.

最近/即将推出的 Meteor 版本具有更好的连接管理支持以及内置支持抓取 IP 地址.结合 login hooks 刚刚合并到 devel 今天的分支,你应该能够直接处理这个问题,或者使用我们将添加到 user-status 包中的东西.

Recent/upcoming versions of Meteor have better support for managing connections as well as built-in support for grabbing IP addresses. Combined with the fact that login hooks were just merged into the devel branch today, you should be able to either handle this directly or use something that we'll add to the user-status package.

如果您需要什么,请随时打开拉取请求.

Feel free to open a pull request if there is something you need.

这篇关于在 Meteor 中创建用户时获取客户端的 ip的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆