Home

How to get the user IP on the server

We can get the Client IP Address from the request object on the server. Most of these information about the client lies in the headers. The following example was written in NodeJS. But it can be utilized in any other server-side language by making some modifications according to your targeted serve language syntax.

const IP = req.headers["x-forwarded-for"]

// Most of the times the IP and realIP will be same.
const realIP = req.headers["x-real-ip"]

// If you want to know about the browser
const userAgent = req.headers["user-agent"]

Want to know about the client ( whether it is Chrome or IE)?

Refer to this post to identify browser



Last Updated on

Next Post: Rules vs Guidelines →

Comments