1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/linuxdash_ynh.git synced 2024-09-03 19:36:07 +02:00
linuxdash_ynh/sources/sh/netstat.php
2014-06-02 13:38:03 +02:00

24 lines
601 B
PHP

<?php
/* this section finds command paths from OS */
$netstat = exec("command -v netstat");
$awk = exec("command -v awk");
$sort = exec("command -v sort");
$uniq = exec("command -v uniq");
/* execute command */
exec("$netstat -ntu | $awk 'NR>2 {sub(/:[^:]+$/, \"\"); print $5}' | $sort | $uniq -c", $result);
header('Content-Type: application/json; charset=UTF-8');
echo "[";
$max = count($result);
for ($i = 0; $i < $max; $i++) {
echo json_encode(preg_split(
'@\s+@',
$result[$i],
null,
PREG_SPLIT_NO_EMPTY
));
echo ($i + 1 == $max)?'':',';
}
echo "]";