samuelmaddock / ip-anonymize

πŸ‘€ Anonymize IP addresses, works with IPv4 and IPv6

Home Page:https://www.npmjs.com/package/ip-anonymize

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ip-anonymize

Build Status codecov npm

πŸ‘€ Anonymize IP addresses, works with IPv4 and IPv6

  • Supports IPv4 βœ”
  • Supports IPv6 βœ”
    • Supports x:x:x:x:x:x:x:x format βœ”
    • Supports x:x:x:x:x:x:d.d.d.d format βœ”
    • Automatically compresses zeros optimally

Installation

$ npm install ip-anonymize --save # Using npm
$ yarn add ip-anonymize # OR use yarn

Usage

const anonymize = require('ip-anonymize')

var ipv4 = '192.168.1.16'
anonymize(ipv4) // '192.168.1.0'

// Use 16-bit mask
anonymize(ipv4, 16) // '192.168.0.0'

var ipv6 = 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff'
anonymize(ipv6) // 'ffff:ff00::'

// Use 16-bit mask (first number is for IPv4, second for IPv6)
anonymize(ipv6, 16, 16) // 'ffff::'

API Documentation

const anonymize = require('ip-anonymize')
anonymize(ip [, v4MaskLength, v6MaskLength])
  • ip: String, The IP address to anonymize
  • v4MaskLength: Number, Number of bits to keep at the beginning of an IPv4 address (default: 24)
  • v6MaskLength: Number, Number of bits to keep at the beginning of an IPv6 address (default: 24)

References

  1. IPv6 representation: RFC3513
  2. IPv6 validator

About

πŸ‘€ Anonymize IP addresses, works with IPv4 and IPv6

https://www.npmjs.com/package/ip-anonymize

License:MIT License


Languages

Language:JavaScript 100.0%