npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ip-device-parser

v1.0.3

Published

Express middleware to parse ip address and device information from request

Downloads

167

Readme

ip-device-parser

NPM Version NPM Downloads Node.js Version

Exress middleware to Parse IP Adress and Client Device Information from the request and it will hold following data.

Installation

$ npm install ip-device-parser

API

const express = require('express');
const ipAndDeviceParser = require('ip-device-parser');

const app = express();
app.use(ipAndDeviceParser());

You can fetch ip and device infor form req.clientInfo where req is express request object

// req.clientInfo
{
  agent: {
    browser: {
      name: 'Chrome Mobile',
      version: '67.0.3396'
    },
    device: {
      name: 'OnePlus ONEPLUS A5000',
      version: '0.0.0'
    },
    os: {
      name: 'Android',
      version: '8.1.0'
    }
  },
  ip: '2xx5:2x5:1xx6:2xx3:2xxc:dxx3:7xx2:6xxa'
}

How It Works

It looks for specific headers in the request and falls back to some defaults if they do not exist.

The following is the order we use to determine the user ip from the request.

  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. True-Client-Ip (Akamai and Cloudflare)
  5. X-Real-IP (Nginx proxy/FastCGI)
  6. X-Cluster-Client-IP (Rackspace LB, Riverbed Stingray)
  7. X-Forwarded, Forwarded-For and Forwarded (Variations of #2)
  8. req.connection.remoteAddress
  9. req.socket.remoteAddress
  10. req.connection.socket.remoteAddress
  11. req.info.remoteAddress

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

References

http://docs.aws.amazon.com/elasticloadbalancing/latest/classic/x-forwarded-headers.html http://stackoverflow.com/a/11285650 http://www.squid-cache.org/Doc/config/forwarded_for/ https://support.cloudflare.com/hc/en-us/articles/200170986-How-does-Cloudflare-handle-HTTP-Request-headers- http://www.rackspace.com/knowledge_center/article/controlling-access-to-linux-cloud-sites-based-on-the-client-ip-address https://splash.riverbed.com/docs/DOC-1926

Thanks Note

~pbojinov's work on IP address headers and request ip package