π€ 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
- Supports
$ npm install ip-anonymize --save # Using npm
$ yarn add ip-anonymize # OR use yarn
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::'
const anonymize = require('ip-anonymize')
anonymize(ip [, v4MaskLength, v6MaskLength])
ip
:String
, The IP address to anonymizev4MaskLength
: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
)
- IPv6 representation: RFC3513
- IPv6 validator