Hello!
I've got the following problem with my script and appreciate any help 😉
First of all what my script does:
- it reads out information about the system connections and running process by using DOS commands like "netstat" or "tasklist" (tasklist is only available at winXP prof., btw)
- it splits every line and every chunks into an array for the netstat- and tasklist-command
- it verifies both arrays by checking the "PID" (it's the only data which exists in both arrays)
- it displays all informations of the PID's in a table
(why? because the netstat command does not display the processname. thats why I fetch the output of the netstat command and the tasklist command)
Example for netstat-command:
http://home.arcor.de/r3in3rs/info/netstat.JPG
Example for tasklist-command:
http://home.arcor.de/r3in3rs/info/tasklist.JPG
ok. That works pretty well, but I also want to add a function to sort the content of my table (by clicking on the tableheader). And here comes the problem :/
Here is my script (cut to the bone):
////////// get information about connections //////////////
$input_net = shell_exec("cmd /c netstat.exe -ano");
$line_net = explode("\n", trim($input_net));
for ($i=0; $i<count($line_net); $i++)
{
$data_net = explode(" ",trim($line_net[$i]));
if($order == 'PID')
{
$key[] = $data_net[4];
}
else if($order == 'Remaddi')
{
$key[] = $data_net[2];
}
else if($order == 'Protokoll')
{
$key[] = $data_net[0];
}
$rows_net[]=$data_net;
}
//////////// get information about processes //////////////
$input_proz = shell_exec("cmd /c tasklist.exe /NH /FO CSV");
$line_proz = explode("\n", trim($input_proz));
for ($i=0; $i<count($line_proz); $i++)
{
$data_proz = explode(",", trim($line_proz[$i]));
if($order == 'Process')
{
$key[] = $data_proz[0];
}
$rows_proz[]=$data_proz;
}
//////////////////////// sort /////////////////////////////
if ($order == 'Process')
{
array_multisort($key, SORT_ASC, SORT_STRING, $rows_proz);
}
if ($order == 'PID')
{
array_multisort($key, SORT_ASC , SORT_NUMERIC,$rows_net);
}
if ($order == 'Adress')
{
array_multisort($key, SORT_ASC , SORT_NUMERIC,$rows_net);
}
if ($order == 'Protokoll')
{
array_multisort($key, SORT_ASC , SORT_REGULAR,$rows_net);
}
////////////////// display table header ///////////////////
echo '<table>
<tr>
<td><a href=my.php?order=PID> PID </a></td>
<td><a href=my.php?order=Process> Process </a></td>
<td><a href=my.php?order=Protokoll>Protokoll</a></td>
<td><a href=my.php?order=Adress> Adress </a></td>
</tr>';
/////////////////// display table lines ///////////////////
foreach($rows_net as $data_net)
{
foreach($rows_proz as $data_proz)
{
// PID == PID
if ($data_net[4] == $data_proz[1])
{
echo '<tr>
<td>$data_net[4]</td>
<td>$data_proz[1]</td>
<td>$data_net[0]</td>
<td>$data_net[2]</td>
</tr>';
}
}
}
echo '</table>';
///////////////////////////////////////////////////////////
?>
Ok. By clicking on the tableheaders is should actually sort it chunks. But that works only for the PIDs (problably because it exists in both arrays). By clicking on the tableheader "process" (for example) it doesn't sort the processes alphabetically. It just sorts the lines in the order they appear in the commando line, if the order has been changed (by sorting by "PID" for example).
Anyone an idea how to fix this ? I think the problem are those two "for each" loops, but I am not entirely shure and dont know how to avoid them.
Thanks a lot for reading and any hint that helps 😉
(and sorry for my bad english :p )