1.0.3 • Published 5 years ago
detect-client-ip v1.0.3
rdetect-client-ip
A module to detect the clients IP address
Installation
npm install detect-client-ip --save
Getting Started
const requestIp = require('detect-client-ip');
// inside middleware handler
const ipMiddleware = function(req, res, next) {
const clientIp = requestIp.retriveIP(req);
next();
};
How It Works
It looks for specific headers in the request and falls back to some defaults if they do not exist.
The user ip is determined by the following order:
X-Client-IP
X-Forwarded-For
(Header may return multiple IP addresses in the format: "client IP, proxy 1 IP, proxy 2 IP", so we take the the first one.)CF-Connecting-IP
(Cloudflare)Fastly-Client-Ip
(Fastly CDN and Firebase hosting header when forwared to a cloud function)True-Client-Ip
(Akamai and Cloudflare)X-Real-IP
(Nginx proxy/FastCGI)X-Cluster-Client-IP
(Rackspace LB, Riverbed Stingray)X-Forwarded
,Forwarded-For
andForwarded
(Variations of #2)req.connection.remoteAddress
req.socket.remoteAddress
req.connection.socket.remoteAddress
req.info.remoteAddress
If an IP address cannot be found, it will return null
.
License
The MIT License (MIT) - 2018