A working version is ready
This commit is contained in:
parent
025fe841de
commit
ac2096776e
56
netcalc.php
56
netcalc.php
@ -1,23 +1,51 @@
|
|||||||
<?php
|
<?php
|
||||||
|
$version="0.1";
|
||||||
|
|
||||||
if (isset($argv[1]))
|
function print_usage()
|
||||||
{
|
{
|
||||||
//$value=$argv[1];
|
print "netcalc.php $GLOBALS[version]\n";
|
||||||
$value=$argv[1];
|
print "Jack-Benny Persson <jack-benny@cyberinfo.se>\n";
|
||||||
if ($value < 0 || $value > 32)
|
print "\n";
|
||||||
{
|
print "Usage: php netcalc.php <netmask>\n";
|
||||||
print "Please enter an integer between 0 and 32 only\n";
|
print "Example: php netcalc.php 24\n";
|
||||||
exit;
|
|
||||||
}
|
|
||||||
$base=32-$value;
|
|
||||||
$netsize=pow(2, $base);
|
|
||||||
$hosts=$netsize-2;
|
|
||||||
print "$hosts\n";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
// Check if first argument is set and and if not, print usage
|
||||||
|
if (!isset($argv[1]))
|
||||||
{
|
{
|
||||||
print "Enter something\n";
|
print_usage();
|
||||||
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$value=$argv[1];
|
||||||
|
|
||||||
|
// Check if our argument was a numeric value or not
|
||||||
|
if (!is_numeric($value))
|
||||||
|
{
|
||||||
|
print "Please enter numbers only (between 0 and 32)\n";
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if the value is between 0 and 32
|
||||||
|
if ($value < 0 || $value > 32)
|
||||||
|
{
|
||||||
|
print "Please enter an integer between 0 and 32 only\n";
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate the diffrent values
|
||||||
|
$base=32-$value;
|
||||||
|
$netsize=pow(2, $base);
|
||||||
|
$hosts=$netsize-2;
|
||||||
|
if ($hosts < 0)
|
||||||
|
{
|
||||||
|
$hosts = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// And now, finally, print the values
|
||||||
|
print "Netmask: $value\n";
|
||||||
|
print "Total number of addresses: $netsize\n";
|
||||||
|
print "Number of usable addresses for hosts: $hosts\n";
|
||||||
|
exit(0);
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user