2020-02-05 22:16:58 +00: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-05-01 03:30:47 +00:00
|
|
|
import (
|
2020-06-08 16:04:31 +00:00
|
|
|
"syscall"
|
2020-05-01 03:30:47 +00:00
|
|
|
"time"
|
2020-06-08 16:04:31 +00:00
|
|
|
|
2020-10-28 16:18:18 +00:00
|
|
|
"golang.org/x/sys/windows"
|
2020-06-08 16:04:31 +00:00
|
|
|
exec "tailscale.com/tempfork/osexec"
|
2020-05-01 03:30:47 +00:00
|
|
|
)
|
2020-03-14 03:53:58 +00:00
|
|
|
|
2020-02-05 22:16:58 +00:00
|
|
|
// Forking on Windows is insanely expensive, so don't do it too often.
|
2020-03-14 03:53:58 +00:00
|
|
|
const pollInterval = 5 * time.Second
|
2020-02-05 22:16:58 +00:00
|
|
|
|
|
|
|
func listPorts() (List, error) {
|
|
|
|
return listPortsNetstat("-na")
|
|
|
|
}
|
|
|
|
|
|
|
|
func addProcesses(pl []Port) ([]Port, error) {
|
2020-10-28 16:18:18 +00:00
|
|
|
if t := windows.GetCurrentProcessToken(); !t.IsElevated() {
|
|
|
|
return listPortsNetstat("-na")
|
|
|
|
}
|
2020-02-05 22:16:58 +00:00
|
|
|
return listPortsNetstat("-nab")
|
|
|
|
}
|
2020-06-08 16:04:31 +00:00
|
|
|
|
|
|
|
func init() {
|
|
|
|
osHideWindow = func(c *exec.Cmd) {
|
|
|
|
c.SysProcAttr = &syscall.SysProcAttr{HideWindow: true}
|
|
|
|
}
|
|
|
|
}
|