Welcome to mirror list, hosted at ThFree Co, Russian Federation.

sys_windows.go « sys « util - github.com/MHSanaei/3x-ui.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 34740ea6b398148821f8d78a29ec251c79ee8091 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
//go:build windows
// +build windows

package sys

import (
	"errors"

	"github.com/shirou/gopsutil/v3/net"
)

func GetConnectionCount(proto string) (int, error) {
	if proto != "tcp" && proto != "udp" {
		return 0, errors.New("invalid protocol")
	}

	stats, err := net.Connections(proto)
	if err != nil {
		return 0, err
	}
	return len(stats), nil
}

func GetTCPCount() (int, error) {
	return GetConnectionCount("tcp")
}

func GetUDPCount() (int, error) {
	return GetConnectionCount("udp")
}