Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
rsteube committed Oct 19, 2023
1 parent 5ac16ff commit 56795c5
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions pkg/actions/net/port.go
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand All @@ -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)
}
}
}
Expand Down

0 comments on commit 56795c5

Please sign in to comment.