markrogoyski / ipv4-subnet-calculator-php

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

Get HostMin and HostMax #3

Closed abhimanyu003 closed 6 years ago

abhimanyu003 commented 7 years ago

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();
markrogoyski commented 7 years ago

Hi, Thanks for the suggestions.

Would getHostsRange() return an array of the min and max hosts?

abhimanyu003 commented 7 years ago

Yes, it must be same getIPAddressRange()

 $sub->getHostsRange();         // [ 192.168.112.1, 192.168.113.254 ]

Im not sure to keep method name as getHostsRange or getHostRange

markrogoyski commented 6 years ago

Hi, These features have been implemented in the newly released version v2.1.0.

Given the following IP address and network:

$sub = new IPv4\SubnetCalculator('192.168.112.203', 23);

Then the following new methods are available.

// Min host
$min_host        = $sub->getMinHost();       // 192.168.112.1
$min_host_quads  = $sub->getMinHostQuads();  // [192, 168, 112, 1]
$min_host_hex    = $sub->getMinHostHex();    // C0A87001
$min_host_binary = $sub->getMinHostBinary(); // 11000000101010000111000000000001

// Max host
$max_host        = $sub->getMaxHost();       // 192.168.113.254
$max_host_quads  = $sub->getMaxHostQuads();  // [192, 168, 113, 254]
$max_host_hex    = $sub->getMaxHostHex();    // C0A871FE
$max_host_binary = $sub->getMaxHostBinary(); // 11000000101010000111000111111110

// Addressable host range
$addressable_host_range = $sub->getAddressableHostRange(); // [192.168.112.1, 192.168.113.254]

Thank you again for the suggestion of adding these features. Sorry for the long delay in implementing them.

Please let me know if you have any other feedback or feature suggestions for IPv4 SubnetCalculator.

Thanks, Mark