2023-02-26 16:59:54 +03:00
|
|
|
//go:build windows
|
|
|
|
// +build windows
|
|
|
|
|
|
|
|
package sys
|
|
|
|
|
|
|
|
import (
|
2023-05-23 02:13:15 +03:00
|
|
|
"errors"
|
|
|
|
|
2024-06-17 22:48:49 +03:00
|
|
|
"github.com/shirou/gopsutil/v4/net"
|
2023-02-26 16:59:54 +03:00
|
|
|
)
|
|
|
|
|
2023-05-23 02:13:15 +03:00
|
|
|
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 16:59:54 +03:00
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
return len(stats), nil
|
|
|
|
}
|
|
|
|
|
2023-05-23 02:13:15 +03:00
|
|
|
func GetTCPCount() (int, error) {
|
|
|
|
return GetConnectionCount("tcp")
|
|
|
|
}
|
|
|
|
|
2023-02-26 16:59:54 +03:00
|
|
|
func GetUDPCount() (int, error) {
|
2023-05-23 02:13:15 +03:00
|
|
|
return GetConnectionCount("udp")
|
2023-02-26 16:59:54 +03:00
|
|
|
}
|