From 8f2ba69751af0e68f32a385e84741b4f42e9addc Mon Sep 17 00:00:00 2001 From: Momchill Zarev Date: Sun, 10 Dec 2023 19:42:49 +0200 Subject: [PATCH] Small fix --- nbscan.go | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/nbscan.go b/nbscan.go index fe82ff7..76e044b 100644 --- a/nbscan.go +++ b/nbscan.go @@ -5,7 +5,7 @@ import ( "net" "time" "os" -// "syscall" + "syscall" "flag" "strings" "errors" @@ -242,29 +242,29 @@ func parseReply(bbuff []byte, result *NBResult) uint16 { } -//func initWindows() { -// stdout := syscall.Handle(os.Stdout.Fd()) -// stderr := syscall.Handle(os.Stdout.Fd()) -// -// var originalMode uint32 -// -// syscall.GetConsoleMode(stdout, &originalMode) -// originalMode |= 0x0004 -// -// syscall.MustLoadDLL("kernel32").MustFindProc("SetConsoleMode").Call(uintptr(stdout), uintptr(originalMode)) -// -// syscall.GetConsoleMode(stderr, &originalMode) -// originalMode |= 0x0004 -// -// syscall.MustLoadDLL("kernel32").MustFindProc("SetConsoleMode").Call(uintptr(stderr), uintptr(originalMode)) -//} +func initWindows() { + stdout := syscall.Handle(os.Stdout.Fd()) + stderr := syscall.Handle(os.Stdout.Fd()) + + var originalMode uint32 + + syscall.GetConsoleMode(stdout, &originalMode) + originalMode |= 0x0004 + + syscall.MustLoadDLL("kernel32").MustFindProc("SetConsoleMode").Call(uintptr(stdout), uintptr(originalMode)) + + syscall.GetConsoleMode(stderr, &originalMode) + originalMode |= 0x0004 + + syscall.MustLoadDLL("kernel32").MustFindProc("SetConsoleMode").Call(uintptr(stderr), uintptr(originalMode)) +} var verbose *bool var quite *bool var json *bool func main() { - //initWindows() + initWindows() flag.Usage = func() { fmt.Println("NBScan v1.0. Scan a list of networks for NetBIOS information") fmt.Println("") @@ -373,7 +373,6 @@ func main() { } if msDelay > 0 { - //var msPassed = -lastSent.Sub(time.Now()).Milliseconds() var msPassed = time.Now().Sub(lastSent).Milliseconds() if msPassed < msDelay { // 10ms correction to compensate this if block @@ -391,7 +390,7 @@ func main() { } }() - for time.Now().Sub(lastComm).Milliseconds() > 1000 * int64(*timeout) { + for time.Now().Sub(lastComm).Milliseconds() < 1000 * int64(*timeout) { time.Sleep(time.Second) } socket.Close()