https://github.com/dharple/ip-analysis
PHP library for analyzing IP addresses
https://github.com/dharple/ip-analysis
iana iana-registry ip ipv4 ipv6 php
Last synced: 4 months ago
JSON representation
PHP library for analyzing IP addresses
- Host: GitHub
- URL: https://github.com/dharple/ip-analysis
- Owner: dharple
- License: bsd-2-clause
- Created: 2020-01-30T01:20:10.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2025-06-03T03:17:49.000Z (4 months ago)
- Last Synced: 2025-06-16T11:00:35.885Z (4 months ago)
- Topics: iana, iana-registry, ip, ipv4, ipv6, php
- Language: PHP
- Homepage:
- Size: 73.2 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# PHP IP Analyzer
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:
```shell
composer require outsanity/ip-analysis
```# Usage
```php
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].[IANA IPv4 Special Address Registry]: https://www.iana.org/assignments/iana-ipv4-special-registry/iana-ipv4-special-registry.xhtml
[IANA IPv6 Special Address Registry]: https://www.iana.org/assignments/iana-ipv6-special-registry/iana-ipv6-special-registry.xhtml
[RIPE IPv6 Reference Card]: https://www.ripe.net/participate/member-support/lir-basics/ipv6_reference_card.pdf
[Wikipedia Reserved IP Addresses]: https://en.wikipedia.org/wiki/Reserved_IP_addresses[IP Analysis Helper]: https://github.com/dharple/ip-analysis-helper