0) { foreach($states as $line) { $line_split = preg_split("/\s+/", $line); $type = array_shift($line_split); $proto = array_shift($line_split); $state = array_pop($line_split); $info = implode(" ", $line_split); /* break up info and extract $srcip and $dstip */ $ends = preg_split("/\-\>?/", $info); if (strpos($info, '->') === FALSE) { $srcinfo = $ends[count($ends) - 1]; $dstinfo = $ends[0]; } else { $srcinfo = $ends[0]; $dstinfo = $ends[count($ends) - 1]; } /* Handle IPv6 */ $parts = explode(":", $srcinfo); $partcount = count($parts); if ($partcount <= 2) { $srcip = trim($parts[0]); $srcport = trim($parts[1]); } else { preg_match("/([0-9a-f:]+)(\[([0-9]+)\])?/i", $srcinfo, $matches); $srcip = $matches[1]; $srcport = trim($matches[3]); } $parts = explode(":", $dstinfo); $partcount = count($parts); if ($partcount <= 2) { $dstip = trim($parts[0]); $dstport = trim($parts[1]); } else { preg_match("/([0-9a-f:]+)(\[([0-9]+)\])?/i", $dstinfo, $matches); $dstip = $matches[1]; $dstport = trim($matches[3]); } addipinfo($srcipinfo, $srcip, $proto, $srcport, $dstport); addipinfo($dstipinfo, $dstip, $proto, $srcport, $dstport); addipinfo($pairipinfo, "{$srcip} -> {$dstip}", $proto, $srcport, $dstport); addipinfo($allipinfo, $srcip, $proto, $srcport, $dstport); addipinfo($allipinfo, $dstip, $proto, $srcport, $dstport); } } function sort_by_ip($a, $b) { return ip2ulong($a) < ip2ulong($b) ? -1 : 1; } function build_port_info($portarr, $proto) { if (!$portarr) return ''; $ports = array(); asort($portarr); foreach (array_reverse($portarr, TRUE) as $port => $count) { $str = ""; $service = getservbyport($port, strtolower($proto)); $port = "{$proto}/{$port}"; if ($service) $port = "{$port} ({$service})"; $ports[] = "{$port}: {$count}"; } return implode($ports, ', '); } function print_summary_table($label, $iparr, $sort = TRUE) { ?>
=gettext("IP");?> | # =gettext("States");?> | =gettext("Proto");?> | # =gettext("States");?> | =gettext("Src Ports");?> | =gettext("Dst Ports");?> |