2020-02-05 14:16:58 -08:00
|
|
|
// Copyright (c) 2020 Tailscale Inc & AUTHORS All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package portlist
|
|
|
|
|
2020-04-30 20:30:47 -07:00
|
|
|
import (
|
2020-06-08 09:04:31 -07:00
|
|
|
"syscall"
|
2020-04-30 20:30:47 -07:00
|
|
|
"time"
|
2020-06-08 09:04:31 -07:00
|
|
|
|
|
|
|
exec "tailscale.com/tempfork/osexec"
|
2020-04-30 20:30:47 -07:00
|
|
|
)
|
2020-03-13 20:53:58 -07:00
|
|
|
|
2020-02-05 14:16:58 -08:00
|
|
|
// Forking on Windows is insanely expensive, so don't do it too often.
|
2020-03-13 20:53:58 -07:00
|
|
|
const pollInterval = 5 * time.Second
|
2020-02-05 14:16:58 -08:00
|
|
|
|
|
|
|
func listPorts() (List, error) {
|
|
|
|
return listPortsNetstat("-na")
|
|
|
|
}
|
|
|
|
|
|
|
|
func addProcesses(pl []Port) ([]Port, error) {
|
|
|
|
return listPortsNetstat("-nab")
|
|
|
|
}
|
2020-06-08 09:04:31 -07:00
|
|
|
|
|
|
|
func init() {
|
|
|
|
osHideWindow = func(c *exec.Cmd) {
|
|
|
|
c.SysProcAttr = &syscall.SysProcAttr{HideWindow: true}
|
|
|
|
}
|
|
|
|
}
|