Skip to content
Snippets Groups Projects
Commit 180303a5 authored by Tibo's avatar Tibo
Browse files

show listening udp ports

parent a825d5a7
No related branches found
No related tags found
No related merge requests found
Pipeline #2065 failed
......@@ -14,24 +14,33 @@ class ListeningPorts extends \App\AbstractSensor
public function report()
{
$record = $this->getLastRecord("netstat-listen-tcp");
if ($record == null) {
$tcp_record = $this->getLastRecord("netstat-listen-tcp");
$udp_record = $this->getLastRecord("netstat-listen-udp");
if ($tcp_record == null && $udp_record == null) {
return "<p>No data available...</p>";
}
$ports = $this->parse($record["netstat-listen-tcp"]);
$ports = array_merge(
$this->parse($tcp_record["netstat-listen-tcp"]),
$this->parse($udp_record["netstat-listen-udp"]));
usort($ports,
function(ListeningPort $port1, ListeningPort $port2) {
return $port1->port - $port2->port;
});
$return = "<table class='table table-sm'>";
$return .= "<tr>"
. "<th>Port</th>"
. "<th>Proto</th>"
. "<th>Bind address</th>"
. "<th>Port</th>"
. "<th>Process</th>"
. "</tr>";
foreach ($ports as $port) {
$return .= "<tr>"
. "<td>" . $port->port . "</td>"
. "<td>" . $port->proto . "</td>"
. "<td>" . $port->bind . "</td>"
. "<td>" . $port->port . "</td>"
. "<td>" . $port->process . "</td>"
. "</tr>";
}
......@@ -49,8 +58,12 @@ class ListeningPorts extends \App\AbstractSensor
* @param string $string
* @return \App\Sensor\ListeningPort[]
*/
public function parse(string $string)
public function parse(?string $string)
{
if ($string == null) {
return [];
}
$values = [];
preg_match_all(self::REGEXP, $string, $values);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment