|
|
@ -75,6 +75,10 @@ func parsePortsNetstat(output string) List {
|
|
|
|
// not interested in non-listener sockets
|
|
|
|
// not interested in non-listener sockets
|
|
|
|
continue
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if strings.HasPrefix(laddr, "127.0.0.1:") || strings.HasPrefix(laddr, "127.0.0.1.") {
|
|
|
|
|
|
|
|
// not interested in loopback-bound listeners
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
}
|
|
|
|
} else if strings.HasPrefix(protos, "udp") {
|
|
|
|
} else if strings.HasPrefix(protos, "udp") {
|
|
|
|
if len(cols) < 3 {
|
|
|
|
if len(cols) < 3 {
|
|
|
|
continue
|
|
|
|
continue
|
|
|
@ -82,6 +86,10 @@ func parsePortsNetstat(output string) List {
|
|
|
|
proto = "udp"
|
|
|
|
proto = "udp"
|
|
|
|
laddr = cols[len(cols)-2]
|
|
|
|
laddr = cols[len(cols)-2]
|
|
|
|
raddr = cols[len(cols)-1]
|
|
|
|
raddr = cols[len(cols)-1]
|
|
|
|
|
|
|
|
if strings.HasPrefix(laddr, "127.0.0.1:") || strings.HasPrefix(laddr, "127.0.0.1.") {
|
|
|
|
|
|
|
|
// not interested in loopback-bound listeners
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
}
|
|
|
|
} else if protos[0] == '[' && len(trimline) > 2 {
|
|
|
|
} else if protos[0] == '[' && len(trimline) > 2 {
|
|
|
|
// Windows: with netstat -nab, appends a line like:
|
|
|
|
// Windows: with netstat -nab, appends a line like:
|
|
|
|
// [description]
|
|
|
|
// [description]
|
|
|
@ -134,16 +142,12 @@ func parsePortsNetstat(output string) List {
|
|
|
|
|
|
|
|
|
|
|
|
//lint:ignore U1000 function is only used on !linux, but we want the
|
|
|
|
//lint:ignore U1000 function is only used on !linux, but we want the
|
|
|
|
// unit test to run on linux, so we don't build-tag it away.
|
|
|
|
// unit test to run on linux, so we don't build-tag it away.
|
|
|
|
func listPortsNetstat(args string) (List, error) {
|
|
|
|
func listPortsNetstat(arg string) (List, error) {
|
|
|
|
exe, err := exec.LookPath("netstat")
|
|
|
|
exe, err := exec.LookPath("netstat")
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("netstat: lookup: %v", err)
|
|
|
|
return nil, fmt.Errorf("netstat: lookup: %v", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
c := exec.Cmd{
|
|
|
|
output, err := exec.Command(exe, arg).Output()
|
|
|
|
Path: exe,
|
|
|
|
|
|
|
|
Args: []string{exe, args},
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
output, err := c.Output()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
xe, ok := err.(*exec.ExitError)
|
|
|
|
xe, ok := err.(*exec.ExitError)
|
|
|
|
stderr := ""
|
|
|
|
stderr := ""
|
|
|
|