cschalenborgh / laravel-ip-anonymizer
IPv4 and IPv6 address anonymizer for Laravel
Installs: 23 612
Dependents: 2
Suggesters: 0
Security: 0
Stars: 5
Watchers: 3
Forks: 0
Open Issues: 0
Requires
- php: >=7.1
Requires (Dev)
- phpunit/phpunit: ^7.5
README
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::