s1lentium / iptools Goto Github PK
View Code? Open in Web Editor NEWPHP Library for manipulating network addresses (IPv4 and IPv6)
License: MIT License
PHP Library for manipulating network addresses (IPv4 and IPv6)
License: MIT License
Hi,
Look this sample from the example please...
`Exclude Subnet from Network:
$excluded = Network::parse('192.0.0.0/8')->exclude(new Network('192.168.1.0/24'));
foreach($excluded as $network) {
echo (string)$network . '
';
}
192.0.0.0/9
192.128.0.0/11
192.160.0.0/13
192.168.0.0/24
192.168.2.0/23
...
192.192.0.0/10
`
If I read correctly, parse a block of 16,777,216 IPs, we extract 255 IPs, and the result is random blocks?!?!? /11 /13 /24 /23 ?!?!?
Or is the delirium? I find it hard to follow the joke ...?
regards,
There have been some changes in master which are not yet in release. Do you plan to tag?
See https://github.com/S1lentium/IPTools/releases , tag 1.2.0 is still in pre-release phase. After a year, can we make it GA?
Does your parser to long integer supports IPv6 too?
echo IP::parse('some IPv6 here')->long //
is something valid with this class?
Hi!
I (we) find the library very useful. I am missing one feature though, for it to completely fulfill my "IP needs".
Would you be open to accepting a pull request adding a expanded(): string
method to the IP
class?
It would work in the following way:
IP::parse('::1')->expanded(); // would return: 0000:0000:0000:0000:0000:0000:0000:0001
IP::parse('127.0.0.1')->expanded(); // would return: 127.0.0.1
I would include test (of course).
I wanted to check in first, because it seems like the library hasn't been updated in a long time.
The IP standards doesn't really see frequent changes either so maybe the library is regarded as "feature complete"? :)
Hi there, seems that the IPTools already have support of php8.1, but you must tag that version
Running this code with PHP 7.4 works fine:
(new Range('49.12.11.10', '49.12.11.35'))->getNetworks();
However, with PHP 8.2, I'm getting this exception:
NetworkException: Exclude subnet not within target network
Great library! Quite easy to use and works perfectly!
There a a few functions to make life easier that are currently not implemented:
Any chance you could add these to the library?
Exclude Subnet from Network:
$excluded = Network::parse('192.0.0.0/8')->exclude(new Network('192.168.1.0/24'));
foreach($excluded as $network) {
echo (string)$network . '<br>';
}
PHP Fatal error: Uncaught TypeError: IPTools\Network::__construct(): Argument #1 ($ip) must be of type IPTools\IP, string given, called in /home/www/test/1.php on line 37 and defined in /home/www/test/vendor/s1lentium/iptools/src/Network.php:32
Stack trace:
#0 /home/www/test/1.php(37): IPTools\Network->__construct()
#1 {main}
thrown in /home/www/test/vendor/s1lentium/iptools/src/Network.php on line 32
Upd.
Error in example:
$excluded = Network::parse('192.0.0.0/8')->exclude(new Network('192.168.1.0/24'));
to
$excluded = Network::parse('192.0.0.0/8')->exclude('192.168.1.0/24');
Given a network in CIDR notation (v4 and v6), is there a means to return certain artifacts without generating the entire array? (For large networks - especially IPv6, this could be a memory consumption event.)
An IPv4 Example (for simplicity):
Given a network of 192.168.10.0/24
$IP->network() = 192.168.10.0
$IP->first() = 192.168.10.1
$IP->nth(100) = 192.168.10.100
$IP->last() = 192.168.10.254
$IP->broadcast() = 192.168.10.255
The ability to obtain those values without having to create a massive array would be extremely helpful. (Not sure if there's a way to do so without creating the array)
Thanks!
Hello, there have not been a stable release for a while and we have to use dev-master@dev
as required version which is not very fancy.
Do you plan to tag a version in a near future?
Thanks!
Iterate over Network IP adresses:
$network = Network::parse('192.168.1.0/24');
foreach($network as $ip) {
echo (string)$ip . '
';
}
192.168.1.0
...
192.168.1.255
Get Network hosts adresses as Range:
$hosts = Network::parse('192.168.1.0/24')->hosts // Range(192.168.1.1, 192.168.1.254);
foreach($hosts as $ip) {
echo (string)$ip . '
';
}
192.168.1.1
...
192.168.1.254
What's the difference?
I need to determine whether IP is in the range
Is it intended that the count of a range is one IP short the expectation? e.g. for 127.0.0.0/31 I would expect a count of 2, not of 1.
Hi,
First of all I want to thank you for this excellent library.
Would it be possible to git tag
this commit 0d9d066 with version number 0.9.0
(or something similar)?
That makes it easier for php 5.3 based projects to depend on this library using composer.
Waiting to hear from you.
Thanks.
Hey, your library seems interesting. Are you planning to tag a stable version at some point? If you do, are you planning to follow SemVer?
thanks!
Is there a possibility to split network to equal subnets using this lib or should it be developed?
$subnets = Network::parse('192.168.0.0/22')->splitEqual('24');
foreach ($network as $ip) {
// 192.168.0.0/24
// 192.168.1.0/24
// 192.168.2.0/24
// 192.168.3.0/24
}
During inheritance of Iterator: Uncaught think\exception\ErrorException: Return type of IPTools\Network::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/wwwroot/project/vendor/s1lentium/iptools/src/Network.php:326
Hello,
Just recently started working with your classes and realized that the number of hosts for a 64 bit mask in an IPv6 address is being erroneously returned.
Delving into the framework I noticed that you're using bcpow function for IPv6 networks and this keeps returning an unexpected value. In fact after testing with different bit masks, it always caps at 9,223,372,036,854,775,808.
I don't know your reasons for not using the pow function but bcpow is completely breaking IPv6.
Hi,
I'm evaluating the usage of this library, have you planned to launch an stable release?
Hello
I found this
$subnets = Network::parse('192.168.0.0/22')->splitEqual('24');
foreach ($network as $ip) {
// 192.168.0.0/24
// 192.168.1.0/24
// 192.168.2.0/24
// 192.168.3.0/24
}
How to merge 4 new subnets to single subnet ?
// 192.168.0.0/24
// 192.168.1.0/24
// 192.168.2.0/24
// 192.168.3.0/24
=> 192.168.0.0/22
Is it possible to use your library to do this ?
Thanks
There are some very useful commit on master that are not release, like the fix for PHP 8.1 e1b7bd3
Thanks
When IP::parse(โฆ)
and other methods are unable to parse the IP, a generic exception is thrown, which makes it difficult to distinguish between parse exceptions and exceptions that may be due to a missing package.
Would creating and throwing IPTools\ParseException
be a decent solution to this? Are there more cases that are currently handled with a generic exception?
I'm happy to provide a PR after discussing the above. The last thing I want to do is introduce poorly-named or poorly-located classes ๐
How to install without Composer?
These IPv6 addresses are failing to be parsed and throw an exception, they are valid according to other validation tools.
Exception on 2607:fb90:a493::
Exception on 2607:fb90:a0b6::
Exception on 2607:fb90:9058::
Exception on 2607:fb90:7cab::
Exception on 2607:fb90:7119::
Exception on 2607:fb90:6ab1::
Exception on 2607:fb90:60a2::
Exception on 2607:fb90:4c53::
Exception on 2607:fb90:1d87::
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.