Files
trihuy-russian/util/sys/sys_windows.go
T

31 lines
492 B
Go
Raw Normal View History

2023-02-26 17:29:54 +03:30
//go:build windows
// +build windows
package sys
import (
2023-05-23 02:43:15 +03:30
"errors"
2024-06-17 21:48:49 +02:00
"github.com/shirou/gopsutil/v4/net"
2023-02-26 17:29:54 +03:30
)
2023-05-23 02:43:15 +03:30
func GetConnectionCount(proto string) (int, error) {
if proto != "tcp" && proto != "udp" {
return 0, errors.New("invalid protocol")
}
stats, err := net.Connections(proto)
2023-02-26 17:29:54 +03:30
if err != nil {
return 0, err
}
return len(stats), nil
}
2023-05-23 02:43:15 +03:30
func GetTCPCount() (int, error) {
return GetConnectionCount("tcp")
}
2023-02-26 17:29:54 +03:30
func GetUDPCount() (int, error) {
2023-05-23 02:43:15 +03:30
return GetConnectionCount("udp")
2023-02-26 17:29:54 +03:30
}