function ROUTE_SHOULD_BE() { $ip = $_POST["ROUTE_SHOULD_BE"]; if (preg_match("#([0-9]+)\$#", $ip, $re)) { $calc_ip = $re[1] . ".0.0.0"; $calc_ip_end = $re[1] . ".255.255.255"; } if (preg_match("#([0-9]+)\\.([0-9]+)\$#", $ip, $re)) { $calc_ip = $re[1] . ".{$re[2]}.0.0"; $calc_ip_end = $re[1] . ".{$re[2]}.255.255"; } if (preg_match("#([0-9]+)\\.([0-9]+)\\.([0-9]+)\$#", $ip, $re)) { $calc_ip = $re[1] . ".{$re[2]}.{$re[3]}.0"; $calc_ip_end = $re[1] . ".{$re[2]}.{$re[3]}.255"; } $ip = new IP(); $cdir = $ip->ip2cidr($calc_ip, $calc_ip_end); $arr = $ip->parseCIDR($cdir); $rang = $arr[0]; $netbit = $arr[1]; $ipv = new ipv4($calc_ip, $netbit); echo "<strong>{$cdir} {$ipv->address()} - {$ipv->netmask()}</strong>"; }
function cdirToNetmask($net) { $results2 = array(); if (preg_match("#(.+?)\\/(.+)#", $net, $re)) { $ip = new ipv4($re[1], $re[2]); $netmask = $ip->netmask(); $ipaddr = $ip->address(); if (preg_match("#[0-9\\.]+#", $netmask)) { return $netmask; } pack_debug("{$net} -> {$ipaddr} - {$netmask} ", __FILE__, __LINE__); } exec("/usr/share/artica-postfix/bin/ipcalc {$net} 2>&1"); pack_debug("/usr/share/artica-postfix/bin/ipcalc {$net} 2>&1", __FILE__, __LINE__); while (list($index, $line) = each($results2)) { if (preg_match("#Netmask:\\s+([0-9\\.]+)#", $line, $re)) { return $re[1]; break; } } }