public function netstat($parse = true)
    {
        $result = trim(shell_exec('netstat -pant'));

        if ($parse) {
            $lines = explode(PHP_EOL, $result);
            unset($lines[0]);
            unset($lines[1]);

            $columns = [
                'Proto',
                'Recv-Q',
                'Send-Q',
                'Local Address',
                'Foreign Address',
                'State',
                'PID/Program',
                'Process Name',
            ];

            $result = [];
            foreach ($lines as $row => $line) {
                $column = array_values(array_filter(explode(' ', $line), 'strlen'));
                foreach ($columns as $col => $key) {
                    $result[$row][$key] = @$column[$col];
                }
            }
            $result = array_values($result);
        }
        
        return $result;
    }
public function netstat($parse = true)
    {
        $result = trim(shell_exec('netstat -pant'));

        if ($parse) {
            $lines = explode(PHP_EOL, $result);
            unset($lines[0]);
            unset($lines[1]);

            $columns = [
                'Proto',
                'Recv-Q',
                'Send-Q',
                'Local Address',
                'Foreign Address',
                'State',
                'PID/Program',
                'Process Name',
            ];

            $result = [];
            foreach ($lines as $row => $line) {
                $column = array_values(array_filter(explode(' ', $line), 'strlen'));
                foreach ($columns as $col => $key) {
                    $result[$row][$key] = @$column[$col];
                }
            }
            $result = array_values($result);
        }
        
        return $result;
    }
public function netstat ( $ parse = true ) { $ result = trim ( shell_exec ( 'netstat -pant' ) ) ; if ( $ parse ) { $ lines = explode ( PHP_EOL , $ result ) ; unset ( $ lines [ 0 ] ) ; unset ( $ lines [ 1 ] ) ; $ columns = [ 'Proto' , 'Recv-Q' , 'Send-Q' , 'Local Address' , 'Foreign Address' , 'State' , 'PID/Program' , 'Process Name' , ] ; $ result = [ ] ; foreach ( $ lines as $ row => $ line ) { $ column = array_values ( array_filter ( explode ( ' ' , $ line ) , 'strlen' ) ) ; foreach ( $ columns as $ col => $ key ) { $ result [ $ row ] [ $ key ] = @ $ column [ $ col ] ; } } $ result = array_values ( $ result ) ; } return $ result ; }
Get netstat output

@return string
Get netstat output