markrogoyski / ipv4-subnet-calculator-php Goto Github PK
View Code? Open in Web Editor NEWNetwork calculator for subnet mask and other classless (CIDR) network information.
License: MIT License
Network calculator for subnet mask and other classless (CIDR) network information.
License: MIT License
Your SubnetCalculator works as is (thanks) but your class creates two properties for network size. You have property declaration for $network. Then, instead of using $network property you create another $network_size property in constructor. The $network_size property is then used throughout your class. $network and $network_size property represents the same value. I changed $network to $network_size in the copy I'm using.
Hello
I use your product to prevent my Website traffic counter for counting traffic for some IP ranges:
$range[$idx ++] = "xxx.yyy.0.0/18";
$range[$idx ++] = "xxx.yyy.32.0/19";
$range[$idx ++] = "xxx.yyy.96.0/19";
$range[$idx ++] = "xxx.yyy.128.0/18";
$range[$idx ++] = "xxx.yyy.128.0/18";
$range[$idx ++] = "xxx.yyy.192.0/18";
$range[$idx ++] = "xxx.yyy.128.0/18";
$range[$idx ++] = "xxx.yyy.228.0/22";
$range[$idx ++] = "xxx.yyy.224.0/19";
$range[$idx ++] = "xxx.yyy.48.0/20";
$range[$idx ++] = "xxx.yyy.208.0/21";
$range[$idx ++] = "xxx.yyy.120.0/21";
$range[$idx ++] = "xxx.yyy.112.0/20";
$range[$idx ++] = "xxx.yyy.108.0/22";
$range[$idx ++] = "xxx.yyy.108.0/22";
$range[$idx ++] = "xxx.yyy.121.0/24";
// One fix (static) IP address
$range[$idx ++] = "xxx.yyy.150.136/255.255.255.255";
But the last line does not work. Are entries for 1 IP addesss like x.x.x.x/255.255.255.255
not possible with your product?
I get that error:
Fatal error: Uncaught UnexpectedValueException: Network size 55 not valid. in C:\Apache24\htdocs\testing\ipv4-subnet-calculator\src\SubnetCalculator.php:705 Stack trace: #0 C:\Apache24\htdocs\testing\ipv4-subnet-calculator\src\SubnetCalculator.php(57): IPv4\SubnetCalculator->validateInputs('xxx.yyy.150.136', '55') #1 C:\Apache24\htdocs\testing\IPTest.php(62): IPv4\SubnetCalculator->__construct('xxx.yyy.150.136', '55') #2 C:\Apache24\htdocs\testing\IPTest.php(83): IPv4\SubnetCalculatorFactory::createInstance('xxx.yyy.150.136', '55') #3 C:\Apache24\htdocs\testing\IPTest.php(96): IPv4\checkIPAddressIsInRange() #4 C:\Apache24\htdocs\testing\IPTestService.php(10): require_once('C:\\Apache24\\htd...') #5 {main} thrown in C:\Apache24\htdocs\testing\ipv4-subnet-calculator\src\SubnetCalculator.php on line 705
Thank you for your Feedback.
Best regards,
Jan
Thanks for great work, it works perfectly.
Whats your thoughts on adding HostMin and HostMax range that can be assigned.
For IP: 192.168.112.203/23
HostMin: 192.168.112.1
HostMax: 192.168.113.254
Example: http://jodies.de/ipcalc?host=192.168.112.203&mask1=23
May be we can add these functions as well.
$sub->getHostsRange();
$sub->getHostMin();
$sub->getHostMax();
Ccomposer require yajra/laravel-datatables-oracle:^8.0
[UnexpectedValueException]
Your github oauth token for github.com contains invalid characters: "${GH_TOKEN}"
Hello. Thanks for the library.
Can we have method for listing all IP in subnet?
Something like:
$sub = new IPv4\SubnetCalculator( '50.50.50.50', 20 );
list($start, $end) = $sub->getIPAddressRange();
$array = [];
$range = range(ip2long($start), ip2long($end));
foreach ($range as $rng){
$array[] = long2ip($rng);
}
return $array;
If you like I can make PR for this or you can add it by yourself.
Also would be nice to have:
If the object is created with a subnetmask of 255.255.255.255 or /32, the min host isn't calculated correctly.
$subnet = new IPv4\SubnetCalculator(192.168.178.23, 32);
$subnet->printSubnetReport();
returns
192.168.178.23/32 Quads Hex Binary
------------------ --------------- -------- --------------------------------
IP Address: 192.168.178.23 C0A8B217 11000000101010001011001000010111
Subnet Mask: 255.255.255.255 FFFFFFFF 11111111111111111111111111111111
Network Portion: 192.168.178.23 C0A8B217 11000000101010001011001000010111
Host Portion: 0.0.0.0 00000000 00000000000000000000000000000000
Number of IP Addresses: 1
Number of Addressable Hosts: 1
IP Address Range: 192.168.178.23 - 192.168.178.23
Broadcast Address: 192.168.178.23
Min Host: 192.168.178.24
Max Host: 192.168.178.23
This also happens with both getMinHost()
and getAddressableHostRange()
.
PHP Deprecated: Return type of IPv4\SubnetCalculator::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice
Hello,
in your composer you show support to PHP 5.3 but in this version it isn't possible to define arrays like this
$array = []
Would it be possible to develop a method where we can get a array of all the ip addresses that exist in the given subnet?
it would be good if the whole thing would also work with ipv6.
Hello, I am developing an ISP management platform and am interested in using your library if that's OK with you. My use case :
When customer is provisioned service,
a) subnet flag is changed to assigned
b) API writes into mikrotik, creating the subnet on the bridge, and assigning the gateway IP to the subnet, and a simple queue is created for the vlan, for the package assigned to the client.
c) installation instructions are then generated for the technician, who simply logs to client end devices, and inserts the statis /30 IP and vlan for the client to get service.
I intend to use your script for two things:
a) creating subnets given a master subnet. e.g. create four /24's from one/22 on the fly.
b) looping through each client subnet and getting the network, gateway, client and broadcast IP's in an array that I can then use to populate my db and write to my routers.
Please let me knowif it is OK to use it, and how you would recommend implementing efficiently
Hi,
Would it be possible to add to the code an n- subnet value.
For example the bc, hostmin, hostmax, etc of the 3th subnet for 123.78.88.90/12 ?
Maybe feeding it as an argument to the script?
Thnx.
Jay
During inheritance of JsonSerializable: Uncaught ErrorException: Return type of IPv4\SubnetCalculator::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\Re
turnTypeWillChange] attribute should be used to temporarily suppress the notice in markrogoyski/ipv4-subnet-calculator/src/SubnetCalculator.php:549
I did not have try to track this or fix it yet, but I am adding it here just for reference. Seems that SubnetCalculator is broken in 8.1 (but not 8.0).
Hello,
would it be possible to integrate arpa from an IP as a function?
replace
/**
* Validate IP address and network.
* @param string $ip IP address in dotted quads format.
* @param int $network_size Network.
* @throws Exception ip or network size not valid
*/
private function validateInputs( $ip, $network_size ) {
if (!filter_var( $ip, FILTER_VALIDATE_IP )) {
throw new Exception("IP address $ip not valid.");
}
if ( ( $network_size < 1 ) || ( $network_size > 32 ) ) {
throw new Exception("Network size $network_size not valid.");
}
}
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.