How to access client IP address in Meteor?

Chet picture Chet · Aug 29, 2013 · Viewed 11.5k times · Source

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?

Answer

Florin Dobre picture Florin Dobre · Mar 26, 2014

Getting the client IP:

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

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;