Added README and changed binary to dotted binary
This commit is contained in:
parent
4105721a08
commit
982cfacee5
24
README.md
Normal file
24
README.md
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
# Netcalc #
|
||||||
|
This is a simple CLI network calculator made in PHP. Usage is pretty straight
|
||||||
|
forward. For example, let say you want to know how many usable addresses you
|
||||||
|
will get with a 26 bit netmask, simply run the script as below:
|
||||||
|
|
||||||
|
php netcalc.php 26
|
||||||
|
|
||||||
|
The above command will give you the following outut:
|
||||||
|
|
||||||
|
Netmask
|
||||||
|
-------
|
||||||
|
In slash notation: 26
|
||||||
|
In dotted decimal: 255.255.255.192
|
||||||
|
In dotted binary: 11111111.11111111.11111111.11000000
|
||||||
|
|
||||||
|
Network size
|
||||||
|
------------
|
||||||
|
Total number of addresses: 64
|
||||||
|
Number of usable addresses for hosts: 62
|
||||||
|
|
||||||
|
## Copyright ##
|
||||||
|
Netcalc is written by Jack-Benny Persson and released under GNU GPL version 2.
|
||||||
|
|
||||||
|
|
10
netcalc.php
10
netcalc.php
@ -59,6 +59,11 @@ function print_netmask($number)
|
|||||||
// Put it together in a binary string
|
// Put it together in a binary string
|
||||||
$binary = "$ones$zeros";
|
$binary = "$ones$zeros";
|
||||||
|
|
||||||
|
// Make it dotted binary format
|
||||||
|
$dotted_binary = substr_replace($binary, ".", 8, 0);
|
||||||
|
$dotted_binary = substr_replace($dotted_binary, ".", 17, 0);
|
||||||
|
$dotted_binary = substr_replace($dotted_binary, ".", 26, 0);
|
||||||
|
|
||||||
// Make it dotted decimal format
|
// Make it dotted decimal format
|
||||||
$firstOctet = base_convert(substr($binary, 0, 8), 2, 10);
|
$firstOctet = base_convert(substr($binary, 0, 8), 2, 10);
|
||||||
$secondOctet = base_convert(substr($binary, 8, 8), 2, 10);
|
$secondOctet = base_convert(substr($binary, 8, 8), 2, 10);
|
||||||
@ -69,9 +74,8 @@ function print_netmask($number)
|
|||||||
print "Netmask\n" ;
|
print "Netmask\n" ;
|
||||||
print "-------\n";
|
print "-------\n";
|
||||||
print "In slash notation: $mask\n";
|
print "In slash notation: $mask\n";
|
||||||
print "In binary: ";
|
print "In dotted decimal: $firstOctet.$secondOctet.$thirdOctet.$forthOctet\n";
|
||||||
print $binary . "\n";
|
print "In dotted binary: $dotted_binary";
|
||||||
print "In dotted decimal: $firstOctet.$secondOctet.$thirdOctet.$forthOctet";
|
|
||||||
print "\n\n";
|
print "\n\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user