This question already has an answer here:
This seems like a very basic question that doesn't have an elegant solution/answer out there.
How can I access the client (remote) IP address from (1) the server or (2) the client?
This question already has an answer here:
This seems like a very basic question that doesn't have an elegant solution/answer out there.
How can I access the client (remote) IP address from (1) the server or (2) the client?
On client
On server:
As Florin mentioned, this is all pretty much integrated with Meteor now, as opposed to the dark ages when we had to do it ourselves. However, I've additionally wrapped it in a package that tracks all open connections and allows you to query for their IPs: https://github.com/mizzao/meteor-user-status. It also does a bunch of other useful stuff.
Getting the client IP:
Without a http request, in the functions you should be able to get the clientIP with:
With a http request and using iron-router and its Router.map function:
In the action function of the targeted route use:
You can use this package: https://github.com/gadicohen/meteor-headers. It gets headers on both client and server.
If you want to do it without a package, you can 'inspire' yourself from the code above, the thing to remember is that prior to 0.6.5 we used the 'hidden'
__meteor_bootstrap__.app
and post 0.6.5 it's recommended to useWebApp.connectHandler
instead.