markrogoyski / ipv4-subnet-calculator-php

Network calculator for subnet mask and other classless (CIDR) network information.
MIT License
168 stars 42 forks source link

What code do i need for only 1 IP address (with 255.255.255.255 subnet mask) #14

Closed kosuodhmwa closed 4 years ago

kosuodhmwa commented 4 years ago

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

markrogoyski commented 4 years ago

Hi,

If you look at the stack trace in your error, you will see this line:

#1 C:\Apache24\htdocs\testing\IPTest.php(62): IPv4\SubnetCalculator->__construct('xx.yyy.150.136', '55') 

It shows that you are trying to construct a SubnetCalculator with a network size of 55. This is not a valid network size. Network sizes go from 1 to 32.

Use a valid network size and it will work.

Mark

kosuodhmwa commented 4 years ago

Hello Mark

Oh... Thank you very much for your feedback!! :-)

Another question: Maybe you can replace the IP address in your post with xxx.yyy.150.136 ?

With best regards, Jan

markrogoyski commented 4 years ago

I've updated it to remove the details.

If you have any other feedback or suggested features don't hesitate to open a new issue.

kosuodhmwa commented 4 years ago

Hello Mark

Thank you very much!

With best regards, Jan

kosuodhmwa commented 4 years ago

Closed.