Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
/ipPublic

Immutable value object for IPv4 and IPv6 addresses, including helper methods and Doctrine support.

License

NotificationsYou must be signed in to change notification settings

darsyn/ip

Repository files navigation

IP is an immutable value object for (both version 4 and 6) IP addresses. Severalhelper methods are provided for ranges, broadcast and network addresses, subnetmasks, whether an IP is a certain type (defined by RFC's), etc.

This project aims for simplicity of use and any contribution towards that goal -whether a bug report, modifications to the codebase, or an improvement to theaccuracy or readability of the documentation - are always welcome.

Full documentation is available in thedocs/ folder.

Compatibility

This library has extensive test coverage using PHPUnit on PHP versions:7.1,7.2,7.3,7.4,8.0,8.1,8.2,8.3 and8.4.

Versions5.x.x of this library are compatible with PHP versions5.6 to8.3 (and will continue to receive bug fixes).

Versions6.x.x of this library are compatible with PHP versions7.1 andabove, and will receive continued support for future versions of PHP (alsoaccepting proposed new features).

Static analysis is performed with PHPStan atmax level on PHP8.4, usingcore, bleeding edge, and deprecation rules.

The Doctrine features for this library have been split off into their ownpackage,darsyn/ip-doctrine.

Brief Example

  • There are three main classes:IPv4,IPv6, andMulti (for bothversion 4 and 6 addresses).
  • Objects are created using a static factory methodIpInterface::factory() instead of the constructor tospeed up internal processes.
  • When usingMulti, the default strategy for representing version 4 addressesinternally isIPv4-mapped.
<?phpdeclare(strict_types=1);useDarsyn\IP\Exception;useDarsyn\IP\Version\IPv4;try {$ip = IPv4::factory('192.168.0.1');}catch (Exception\InvalidIpAddressException$e) {exit('The IP address supplied is invalid!');}$companyNetwork = IPv4::factory('216.58.198.174');if (!$ip->inRange($companyNetwork,25)) {thrownew \Exception('Request not from a known company IP address.');}// Is it coming from the local network?if (!$ip->isPrivateUse()) {record_visit($ip->getBinary(),$_SERVER['HTTP_USER_AGENT']);}

Code of Conduct

This project includes and adheres to theContributor Covenant as a Code ofConduct.

License

Please see theseparate license file included in this repositoryfor a full copy of the MIT license, which this project is licensed under.

Authors

If you make a contribution (submit a pull request), don't forget to add yourname here!


[8]ページ先頭

©2009-2025 Movatter.jp