outsanity / ip-analysis
Library for analyzing IP addresses
Installs: 1 210
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 2
Forks: 0
Open Issues: 1
Requires
- php: >=7.4.3
- symfony/http-foundation: >=5.4
Requires (Dev)
- outsanity/phpcs: >=0.4.0
- phpstan/phpstan: ^1.12.6
- phpunit/phpunit: ^9.6.21
- rector/rector: ^1.2.7
- squizlabs/php_codesniffer: ^3.10.3
- symfony/serializer: >=5.4.44
Suggests
- symfony/serializer: Serialization support for SpecialAddressBlock
README
Analyzes IP addresses to help programmatically identify IPs that are globally reachable, or not, and find out additional details about the IP.
Installation
If you're using composer, run:
composer require outsanity/ip-analysis
Usage
<?php require 'vendor/autoload.php'; use Outsanity\IpAnalysis\IpAnalysis; $ip = new IpAnalysis('127.0.0.1'); echo 'documentation: ' . ($ip->isDocumentation() ? 'yes' : 'no') . "\n"; // 192.0.2.65, 2001:db8:1:3::2 echo 'global: ' . ($ip->isGlobal() ? 'yes' : 'no') . "\n"; // 8.8.8.8, 2001:4860:4860::8888 echo 'loopback: ' . ($ip->isLoopback() ? 'yes' : 'no') . "\n"; // 127.0.0.1, ::1 echo 'multicast: ' . ($ip->isMulticast() ? 'yes' : 'no') . "\n"; // 224.0.1.1, ff00::101 echo 'private: ' . ($ip->isPrivateNetwork() ? 'yes' : 'no') . "\n"; // 10.0.0.1, 192.168.0.1, fd11:1111:1111::1 echo 'subnet: ' . ($ip->isLocalNetwork() ? 'yes' : 'no') . "\n"; // 169.254.0.1, fe80::6450:6a14:93ba:de09
Expected output:
documentation: no
global: no
loopback: yes
multicast: no
private: no
subnet: no
Build Support
A second package, IP Analysis Helper, converts the IANA .csv
rule file into
SpecialAddressBlock
entities. These live in
Outsanity\IpAnalysis\SpecialAddressBlock\Factory::$allRaw
.
Thanks
The rules come from the IANA IPv4 Special Address Registry and the IANA IPv6 Special Address Registry.
Additional help came from the Wikipedia Reserved IP Addresses page and the RIPE IPv6 Reference Card.