I would like to get the user IP address in my meteor application, on the server side, so that I can log the IP address with a bunch of things (for example: non-registered users subscribing to a mailing list, or just doing anything important).
I know that the IP address 'seen' by the server can be different than the real source address when there are reverse proxies involved. In such situations, X-Forwarded-For
header should be parsed to get the real public IP address of the user. Note that parsing X-Forwarded-For
should not be automatic (see http://www.openinfo.co.uk/apache/index.html for a discussion of potential security issues).
External reference: This question came up on the meteor-talk mailing list in august 2012 (no solution offered).
First, click on your Start Menu and type cmd in the search box and press enter. A black and white window will open where you will type ipconfig /all and press enter. There is a space between the command ipconfig and the switch of /all. Your ip address will be the IPv4 address.
Similar to the TimDog answer but works with newer versions of Meteor:
var Fiber = Npm.require('fibers'); __meteor_bootstrap__.app .use(function(req, res, next) { Fiber(function () { console.info(req.connection.remoteAddress); next(); }).run(); });
This needs to be in your top-level server code (not in Meteor.startup)
1 - Without a http request, in the functions you should be able to get the clientIP with:
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
2 - With a http request and using iron-router and its Router.map function:
In the action function of the targeted route use:
clientIp = this.request.connection.remoteAddress;
3 - using Meteor.onConnection function:
Meteor.onConnection(function(conn) { console.log(conn.clientAddress); });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With