Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
1062477b42 | |||
308ba920a9 | |||
b1aa5d6005 | |||
07993c0508 |
15
LICENSE
Normal file
15
LICENSE
Normal file
@ -0,0 +1,15 @@
|
||||
Copyright (C) 2014 Jack-Benny Persson <jack-benny@cyberinfo.se>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
@ -5,6 +5,10 @@ will get with a 26 bit netmask, simply run the script as below:
|
||||
|
||||
php netcalc.php 26
|
||||
|
||||
Or you `chmod +x netcalc.php` and run it as below:
|
||||
|
||||
./netcalc.php 26
|
||||
|
||||
The above command will give you the following outut:
|
||||
|
||||
Netmask
|
||||
|
19
netcalc.php
Normal file → Executable file
19
netcalc.php
Normal file → Executable file
@ -1,3 +1,4 @@
|
||||
#!/usr/bin/php
|
||||
<?php
|
||||
|
||||
/*
|
||||
@ -56,8 +57,22 @@ function print_netmask($number)
|
||||
}
|
||||
unset($i);
|
||||
|
||||
// Put it together in a binary string
|
||||
// Special cases when netmask is 0 or 32
|
||||
if ($mask == 0)
|
||||
{
|
||||
// If the network mask is 0, then just put 32 zeros in the string
|
||||
$binary = "00000000000000000000000000000000";
|
||||
}
|
||||
elseif ($mask == 32)
|
||||
{
|
||||
// If the network mask is 32, then just put 32 ones in the string
|
||||
$binary = "11111111111111111111111111111111";
|
||||
}
|
||||
else
|
||||
{
|
||||
// Else put the ones and zeros together in a binary string
|
||||
$binary = "$ones$zeros";
|
||||
}
|
||||
|
||||
// Make it dotted binary format
|
||||
$dotted_binary = substr_replace($binary, ".", 8, 0);
|
||||
@ -85,6 +100,8 @@ function print_values($value)
|
||||
$base=32-$value;
|
||||
$netsize=pow(2, $base);
|
||||
$hosts=$netsize-2;
|
||||
|
||||
// We don't want negative values
|
||||
if ($hosts < 0)
|
||||
{
|
||||
$hosts = 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user