0) { foreach ($states as $line) { $line_split = preg_split("/\s+/", $line); $iface = array_shift($line_split); $proto = array_shift($line_split); $state = array_pop($line_split); $info = implode(" ", $line_split); /* Handle NAT cases Replaces an external IP + NAT by the internal IP */ if (strpos($info, ') ->') !== FALSE) { /* Outbound NAT */ $info = preg_replace('/(\S+) \((\S+)\)/U', "$2", $info); } elseif (strpos($info, ') <-') !== FALSE) { /* Inbound NAT/Port Forward */ $info = preg_replace('/(\S+) \((\S+)\)/U', "$1", $info); } /* 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) { $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) { if ($sort) { uksort($iparr, "sort_by_ip"); } ?>
=gettext("IP");?> | # =gettext("States");?> | =gettext("Protocol");?> | # =gettext("States");?> | =gettext("Source Ports");?> | =gettext("Dest. Ports");?> |
---|---|---|---|---|---|
>=$ip;?> | class="text-center">=$ipinfo['seen'];?> | $protoinfo): ?> 1 && $i > 0): ?>||||
=$proto;?> | =$protoinfo['seen'];?> | =count($protoinfo['srcports']);?> | =count($protoinfo['dstports']);?> |