{"id":18517870,"url":"https://github.com/s1lentium/iptools","last_synced_at":"2025-05-16T01:06:23.160Z","repository":{"id":14241856,"uuid":"16949165","full_name":"S1lentium/IPTools","owner":"S1lentium","description":"PHP Library for manipulating network addresses (IPv4 and IPv6)","archived":false,"fork":false,"pushed_at":"2024-05-03T19:27:38.000Z","size":83,"stargazers_count":229,"open_issues_count":18,"forks_count":54,"subscribers_count":16,"default_branch":"master","last_synced_at":"2025-05-16T01:06:15.092Z","etag":null,"topics":["ip","ip-adress","ip-tools","ip-utils","iptools","ipv4","ipv6","network","networking","php","range","subnet"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/S1lentium.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-02-18T13:06:53.000Z","updated_at":"2025-04-22T22:27:18.000Z","dependencies_parsed_at":"2024-06-18T11:18:02.451Z","dependency_job_id":null,"html_url":"https://github.com/S1lentium/IPTools","commit_stats":{"total_commits":77,"total_committers":13,"mean_commits":5.923076923076923,"dds":0.4285714285714286,"last_synced_commit":"88be1aaaab3c50fc131ebe778e246215ff006d8e"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/S1lentium%2FIPTools","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/S1lentium%2FIPTools/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/S1lentium%2FIPTools/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/S1lentium%2FIPTools/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/S1lentium","download_url":"https://codeload.github.com/S1lentium/IPTools/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254448579,"owners_count":22072764,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ip","ip-adress","ip-tools","ip-utils","iptools","ipv4","ipv6","network","networking","php","range","subnet"],"created_at":"2024-11-06T17:10:01.636Z","updated_at":"2025-05-16T01:06:18.151Z","avatar_url":"https://github.com/S1lentium.png","language":"PHP","readme":"# IPTools\n\nPHP Library for manipulating network addresses (IPv4 and IPv6).\n\n[![Build Status](https://travis-ci.org/S1lentium/IPTools.svg)](https://travis-ci.org/S1lentium/IPTools)\n[![Coverage Status](https://coveralls.io/repos/S1lentium/IPTools/badge.svg?branch=master\u0026service=github)](https://coveralls.io/github/S1lentium/IPTools?branch=master)\n[![Code Climate](https://codeclimate.com/github/S1lentium/IPTools/badges/gpa.svg)](https://codeclimate.com/github/S1lentium/IPTools)\n\n[![PHP 5.6](https://img.shields.io/badge/PHP-5.6-8892BF.svg)](http://php.net)\n[![PHP 7.0](https://img.shields.io/badge/PHP-7.0-8892BF.svg)](http://php.net)\n[![PHP 8.0](https://img.shields.io/badge/PHP-8.0-8892BF.svg)](http://php.net)\n\n## Installation\nComposer:\nRun in command line:\n```\ncomposer require s1lentium/iptools\n```\nor put in composer.json:\n```json\n{\n    \"require\": {\n        \"s1lentium/iptools\": \"*\"\n    }\n}\n```\n\n## Usage\n\n### IP Operations\n```php\n$ip = new IP('192.168.1.1');\necho $ip-\u003eversion;// IPv4\n```\n\n```php\n$ip = new IP('fc00::');\necho $ip-\u003eversion; // IPv6\n```\n\n**Parsing IP from integer, binary and hex:**\n```php\necho (string)IP::parse(2130706433); // 127.0.0.1\necho (string)IP::parse('0b11000000101010000000000100000001') // 192.168.1.1\necho (string)IP::parse('0x0a000001'); // 10.0.0.1\n```\nor:\n```php\necho (string)IP::parseLong(2130706433); // 127.0.0.1\necho (string)IP::parseBin('11000000101010000000000100000001'); // 192.168.1.1\necho (string)IP::parseHex('0a000001'); // 10.0.0.1\n```\n\n**Converting IP to other formats:**\n```php\necho IP::parse('192.168.1.1')-\u003ebin // 11000000101010000000000100000001\necho IP::parse('10.0.0.1')-\u003ehex // 0a000001\necho IP::parse('127.0.0.1')-\u003elong // 2130706433\n```\n\n#### Other public properties:\n\n`maxPrefixLength`\nThe max number of bits in the address representation: 32 for IPv4, 128 for IPv6.\n\n`octetsCount`\nThe count of octets in IP address: 4 for IPv4, 16 for IPv6\n\n`reversePointer`\nThe name of the reverse DNS PTR for the address:\n```php\necho new IP::parse('192.0.2.5')-\u003ereversePointer // 5.2.0.192.in-addr.arpa\necho new IP::parse('2001:db8::567:89ab')-\u003ereversePointer // b.a.9.8.7.6.5.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa\n```\n\n### Network Operations\n```php\necho Network::parse('192.0.0.1 255.0.0.0')-\u003eCIDR; // 192.0.0.0/8\necho (string)Network::parse('192.0.0.1/8')-\u003enetmask; // 255.0.0.0\necho (string)Network::parse('192.0.0.1'); // 192.0.0.1/32\n```\n\n**Exclude IP from Network:**\n```php\n$excluded = Network::parse('192.0.0.0/8')-\u003eexclude(new IP('192.168.1.1'));\nforeach($excluded as $network) {\n\techo (string)$network . '\u003cbr\u003e';\n}\n```\n\t192.0.0.0/9\n\t192.128.0.0/11\n\t192.160.0.0/13\n\t192.168.0.0/24\n\t192.168.1.0/32\n\t192.168.1.2/31\n\t...\n\t192.192.0.0/10\n\n**Exclude Subnet from Network:**\n```php\n$excluded = Network::parse('192.0.0.0/8')-\u003eexclude(new Network('192.168.1.0/24'));\nforeach($excluded as $network) {\n\techo (string)$network . '\u003cbr\u003e';\n}\n```\n\t192.0.0.0/9\n\t192.128.0.0/11\n\t192.160.0.0/13\n\t192.168.0.0/24\n\t192.168.2.0/23\n\t...\n\t192.192.0.0/10\n\n**Split network into equal subnets**\n```php\n$networks = Network::parse('192.168.0.0/22')-\u003emoveTo('24');\nforeach ($networks as $network) {\n\techo (string)$network . '\u003cbr\u003e';\n}\n```\n\t192.168.0.0/24\n\t192.168.1.0/24\n\t192.168.2.0/24\n\t192.168.3.0/24\n\n**Iterate over Network IP adresses:**\n```php\n$network = Network::parse('192.168.1.0/24');\nforeach($network as $ip) {\n\techo (string)$ip . '\u003cbr\u003e';\n}\n```\n\t192.168.1.0\n\t...\n\t192.168.1.255\n\n**Get Network hosts adresses as Range:**\n```php\n$hosts = Network::parse('192.168.1.0/24')-\u003ehosts // Range(192.168.1.1, 192.168.1.254);\nforeach($hosts as $ip) {\n\techo (string)$ip . '\u003cbr\u003e';\n}\n```\n\t192.168.1.1\n\t...\n\t192.168.1.254\n\n**Count Network IP adresses**\n```php\necho count(Network::parse('192.168.1.0/24')) // 254\n```\n\n### Range Operations\n**Define the range in different formats:**\n```php\n$range = new Range(new IP('192.168.1.0'), new IP('192.168.1.255'));\n$range = Range::parse('192.168.1.0-192.168.1.255');\n$range = Range::parse('192.168.1.*');\n$range = Range::parse('192.168.1.0/24');\n```\n**Check if IP is within Range:**\n```php\necho Range::parse('192.168.1.1-192.168.1.254')-\u003econtains(new IP('192.168.1.5')); // true\necho Range::parse('::1-::ffff')-\u003econtains(new IP('::1234')); // true\n```\n\n**Iterate over Range IP adresses:**\n```php\n$range = Range::parse('192.168.1.1-192.168.1.254');\nforeach($range as $ip) {\n\techo (string)$ip . '\u003cbr\u003e';\n}\n```\n\t192.168.1.1\n\t...\n\t192.168.1.254\n\n**Get Networks that fit into a specified range of IP Adresses:**\n```php\n$networks = Range::parse('192.168.1.1-192.168.1.254')-\u003egetNetworks();\n\nforeach($networks as $network) {\n\techo (string)$network . '\u003cbr\u003e';\n}\n```\n\t192.168.1.1/32\n\t192.168.1.2/31\n\t192.168.1.4/30\n\t192.168.1.8/29\n\t192.168.1.16/28\n\t192.168.1.32/27\n\t192.168.1.64/26\n\t192.168.1.128/26\n\t192.168.1.192/27\n\t192.168.1.224/28\n\t192.168.1.240/29\n\t192.168.1.248/30\n\t192.168.1.252/31\n\t192.168.1.254/32\n\n**Count IP adresses in Range**\n```php\necho count(Range::parse('192.168.1.1-192.168.1.254')) // 254\n```\n\n# License\nThe library is released under the [MIT](https://opensource.org/licenses/MIT).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fs1lentium%2Fiptools","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fs1lentium%2Fiptools","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fs1lentium%2Fiptools/lists"}