Show code - CODE/PHP/ip_use.php


<?php
include("ip_lib.php");
do_header();
if ( $_POST )
{
$ip_address = $_POST["IpAddress"];
$netmask = $_POST['Netmask'];
if (!valid_ipv4($ip_address))
{
echo_line_br("That is not a valid network number");
}
$network = get_network($ip_address, $netmask);
echo_line_br("Given your ip address $ip_address and your netmask $netmask, your network address is $network" );
$ip_class = get_ip_class( $network );
$borrow = 4;
$netmask_by_bits_left = subnet_mask_by_bits_left($borrow );
//verify_subnet_mask($netmask);
$broadcast = get_broadcast($ip_address, $netmask);
$network_range = get_network_range(get_broadcast($ip_address, $netmask), get_network($ip_address, $netmask));
echo_line_br( "
The class (without classless check) is $ip_class<br>
The netmask (nothing to do with your entry) after borrowing $borrow bits is $netmask_by_bits_left<br>
The broadcast is $broadcast<br>
The network range is $network_range");
}
else
{
do_form();
}
do_footer();
function echo_line($text_in="")
{
echo "$text_in\n";
}
function echo_line_br($text_in="")
{
echo "$text_in<br>\n";
}
function do_header()
{
echo_line("<html><head><title>IP Matters</title></head><body>");
echo_line();
}
function do_footer()
{
echo_line("</body></html>");
}
function do_form()
{
echo_line( "<form action=\"" . $_SERVER['script_name'] . "\" method=\"POST\" name=\"wizroom\">");
echo_line("<pre>");
echo_line("\nIp Address: <input name=\"IpAddress\" type=\"text\" size=15 maxlength=15>");
echo_line("\nNetmask: <input name=\"Netmask\" type=\"text\" size=15 maxlength=15>");
echo_line("\nShow the network number for the given ip and netmask combination\n");
echo_line("\n<input name=\"Submit\" type=\"submit\" size=14 value=\"Submit\">");
echo_line("</pre>");
echo_line("</form>");
}
?>