cschalenborgh/laravel-ip-anonymizer

IPv4 and IPv6 address anonymizer for Laravel

1.0.6 2019-05-01 15:31 UTC

This package is auto-updated.

Last update: 2024-11-29 05:50:59 UTC


README

Latest Version on Packagist Build Status Code Coverage (GitHub) StyleCI Total Downloads License: MIT

Description

You can use this package to easily anonymize IP addresses in your Laravel application. Requires PHP 7.1 or higher.

Installation

You can install the package via composer:

composer require cschalenborgh/laravel-ip-anonymizer

The service provider will automatically get registered. Or you may manually add the service provider in your config/app.php file:

'providers' => [
    // ...
    Cschalenborgh\IpAnonymizer\IpAnonymizerServiceProvider::class,
];

Usage

echo IpAnonymizer::anonymizeIp('133.242.241.12'); 
// returns 133.242.241.0
echo IpAnonymizer::anonymizeIp('133.242.241.12', '255.255.0.0'); 
// returns 133.242.0.0
echo IpAnonymizer::anonymizeIp('2001:db8:85a3::1319:8a2e:370:7344', 'ipv6'); 
// returns 2001:db8:85a3::
echo IpAnonymizer::anonymizeIp('2001:db8:85a3::1319:8a2e:370:7344', 'ipv6', 'ffff:ffff:0000:0000:0000:0000:0000:0000'); 
// returns 2001:db8::
echo (new IpAnonymizer())->anonymizeIPv4('133.242.241.12');
// returns 133.242.241.0

echo (new IpAnonymizer())->anonymizeIPv4('133.242.241.12', '255.0.0.0');
// returns 133.0.0.0

echo (new IpAnonymizer())->anonymizeIPv6('2001:db8:85a3::1319:8a2e:370:7344');
// returns 2001:db8:85a3::

echo (new IpAnonymizer())->anonymizeIPv6('2001:db8:85a3::1319:8a2e:370:7344', 'ffff:ffff:0000:0000:0000:0000:0000:0000');
// returns 2001:db8::