cmd/cli: check local DNS using Windows API

This commit is contained in:
Cuong Manh Le
2024-12-19 21:34:21 +07:00
committed by Cuong Manh Le
parent a56711796f
commit 71e327653a
5 changed files with 62 additions and 19 deletions
+22
View File
@@ -2,7 +2,9 @@ package cli
import (
"os"
"strings"
"syscall"
"unsafe"
"golang.org/x/sys/windows"
)
@@ -79,3 +81,23 @@ func openLogFile(path string, mode int) (*os.File, error) {
return os.NewFile(uintptr(handle), path), nil
}
const processEntrySize = uint32(unsafe.Sizeof(windows.ProcessEntry32{}))
// hasLocalDnsServerRunning reports whether we are on Windows and having Dns server running.
func hasLocalDnsServerRunning() bool {
h, e := windows.CreateToolhelp32Snapshot(windows.TH32CS_SNAPPROCESS, 0)
if e != nil {
return false
}
p := windows.ProcessEntry32{Size: processEntrySize}
for {
e := windows.Process32Next(h, &p)
if e != nil {
return false
}
if strings.ToLower(windows.UTF16ToString(p.ExeFile[:])) == "dns.exe" {
return true
}
}
}