All Projects → pbojinov → Request Ip

pbojinov / Request Ip

Licence: mit
A Node.js module for retrieving a request's IP address on the server.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Request Ip

Ship
A simple, handy network addressing multitool with plenty of features
Stars: ✭ 81 (-83.83%)
Mutual labels:  ip, address
FGRoute
Get your device ip address, router ip or wifi ssid
Stars: ✭ 128 (-74.45%)
Mutual labels:  address, ip
Spoofmac
💼 Change your MAC address for debugging
Stars: ✭ 2,687 (+436.33%)
Mutual labels:  ip, address
Gaxios
An HTTP request client that provides an axios like interface over top of node-fetch. Super lightweight. Supports proxies and all sorts of other stuff.
Stars: ✭ 301 (-39.92%)
Mutual labels:  request, npm
private-ip
Check if IP address is private.
Stars: ✭ 26 (-94.81%)
Mutual labels:  address, ip
Phin
Node HTTP client
Stars: ✭ 449 (-10.38%)
Mutual labels:  request, npm
Cli
the package manager for JavaScript
Stars: ✭ 5,277 (+953.29%)
Mutual labels:  npm
Vanilla Framework
From community websites to web applications, this CSS framework will help you achieve a consistent look and feel.
Stars: ✭ 476 (-4.99%)
Mutual labels:  npm
Salus
Security scanner coordinator
Stars: ✭ 441 (-11.98%)
Mutual labels:  npm
React Native Blurhash
🖼️ A library to show colorful blurry placeholders while your content loads.
Stars: ✭ 430 (-14.17%)
Mutual labels:  npm
Ultra Runner
🏃⛰ Ultra fast monorepo script runner and build tool
Stars: ✭ 496 (-1%)
Mutual labels:  npm
Migrate Mongo
A database migration tool for MongoDB in Node
Stars: ✭ 481 (-3.99%)
Mutual labels:  npm
Cnp3
Computer Networking : Principles, Protocols and Practice (first and second edition, third edition is being written on https://github.com/cnp3/ebook)
Stars: ✭ 471 (-5.99%)
Mutual labels:  ip
Swiftyjson
The better way to deal with JSON data in Swift.
Stars: ✭ 21,042 (+4100%)
Mutual labels:  request
Fast Cgi Client
A PHP fast CGI client for sending requests (a)synchronously to PHP-FPM
Stars: ✭ 478 (-4.59%)
Mutual labels:  request
Information collection handbook
Handbook of information collection for penetration testing and src
Stars: ✭ 447 (-10.78%)
Mutual labels:  ip
Jquery.thailand.js
ตัวช่วยกรอกที่อยู่ที่ดีที่สุดในไทย ไม่ต้องใช้ Server Side!
Stars: ✭ 490 (-2.2%)
Mutual labels:  address
Dependency Check
checks which modules you have used in your code and then makes sure they are listed as dependencies in your package.json
Stars: ✭ 435 (-13.17%)
Mutual labels:  npm
Sppermissions
Ask permissions with ready-use interface. You can check status permission and if it has been requested before. Support SwiftUI.
Stars: ✭ 4,701 (+838.32%)
Mutual labels:  request
Npm Trends
NPM package comparison
Stars: ✭ 479 (-4.39%)
Mutual labels:  npm

request-ip

A tiny Node.js module for retrieving a request's IP address.

Coverage Status npm version

Installation

npm install request-ip --save

Getting Started

const requestIp = require('request-ip');

// inside middleware handler
const ipMiddleware = function(req, res, next) {
    const clientIp = requestIp.getClientIp(req); 
    next();
};

// on localhost you'll see 127.0.0.1 if you're using IPv4 
// or ::1, ::ffff:127.0.0.1 if you're using IPv6

As Connect Middleware

const requestIp = require('request-ip');
app.use(requestIp.mw())

app.use(function(req, res) {
    const ip = req.clientIp;
    res.end(ip);
});

To see a full working code for the middleware, check out the examples folder.

The connect-middleware also supports retrieving the ip address under a custom attribute name, which also works as a container for any future settings.

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:

  1. X-Client-IP
  2. 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.)
  3. CF-Connecting-IP (Cloudflare)
  4. Fastly-Client-Ip (Fastly CDN and Firebase hosting header when forwared to a cloud function)
  5. True-Client-Ip (Akamai and Cloudflare)
  6. X-Real-IP (Nginx proxy/FastCGI)
  7. X-Cluster-Client-IP (Rackspace LB, Riverbed Stingray)
  8. X-Forwarded, Forwarded-For and Forwarded (Variations of #2)
  9. req.connection.remoteAddress
  10. req.socket.remoteAddress
  11. req.connection.socket.remoteAddress
  12. req.info.remoteAddress

If an IP address cannot be found, it will return null.

Samples Use Cases

  • Getting a user's IP for geolocation.

Running the Tests

Make sure you have the necessary dev dependencies needed to run the tests:

npm install

Run the integration tests

npm test

Release Notes

See the wonderful changelog

To easily generate a new changelog, install github-changelog-generator then run npm run changelog.

Contributors

  • Thanks to @osherx for adding the connect-middleware.
  • Thanks to @raunc for adding Squid proxy support.
  • Thanks to @fluxsauce for adding CF-Connecting-IP, True-Client-IP, and ES6 support.
  • Thanks to @vishalvijay for adding Fastly/Firebase hosting support.

License

The MIT License (MIT) - 2018

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].