如何在Meteor中访问客户端IP地址?

Che*_*het 8 javascript node.js meteor meteorite

这似乎是一个非常基本的问题,没有优雅的解决方案/答案.

如何从(1)服务器或(2)客户端访问客户端(远程)IP地址?

Flo*_*bre 15

获取客户端IP:

没有http请求,在函数中你应该能够获得clientIP:

clientIP = this.connection.clientAddress;
//EX: you declare a submitForm function with Meteor.methods and 
//you call it from the client with Meteor.call().
//In submitForm function you will have access to the client address as above
Run Code Online (Sandbox Code Playgroud)

使用http请求并使用iron-router及其Router.map函数:

在目标路线的动作功能中使用:

clientIp = this.request.connection.remoteAddress;
Run Code Online (Sandbox Code Playgroud)


And*_*Mao 7

正如Florin所说,现在这几乎与Meteor融为一体,而不是我们不得不自己做的黑暗时代.但是,我还将它包装在跟踪所有打开连接的包中,并允许您查询其IP:https://github.com/mizzao/meteor-user-status.它还做了许多其他有用的东西.