From 56795c5a717011345f517cd711a07195168ebc3f Mon Sep 17 00:00:00 2001 From: rsteube Date: Thu, 19 Oct 2023 16:14:49 +0200 Subject: [PATCH] tmp --- pkg/actions/net/port.go | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/pkg/actions/net/port.go b/pkg/actions/net/port.go index 0408a4132a..fc6d4a9b70 100644 --- a/pkg/actions/net/port.go +++ b/pkg/actions/net/port.go @@ -87,7 +87,7 @@ func actionUsedPortsNetstat() carapace.Action { return carapace.ActionExecCommand("netstat", "-abon")(func(output []byte) carapace.Action { lines := strings.Split(string(output), "\r\n") vals := make([]string, 0) - for index, line := range lines { + for index, line := range lines[:len(lines)-1] { if fields := strings.Fields(line); len(fields) > 3 { switch { case fields[3] != "LISTENING": @@ -97,14 +97,11 @@ func actionUsedPortsNetstat() carapace.Action { } if splitted := strings.Split(fields[1], ":"); len(splitted) > 1 { - executable := strings.TrimSpace(lines[index-1]) - switch { - case strings.HasPrefix(executable, "["): - executable = executable[1 : len(executable)-1] - default: - executable = "unknown" + service := strings.TrimSpace(lines[index+1]) + if strings.HasPrefix(service, "[") { + service = service[1 : len(service)-1] } - vals = append(vals, splitted[len(splitted)-1], "used by: "+executable) + vals = append(vals, splitted[len(splitted)-1], "used by: "+service) } } }