sys_darwin.go 367 B

123456789101112131415161718192021222324
  1. //go:build darwin
  2. // +build darwin
  3. package sys
  4. import (
  5. "github.com/shirou/gopsutil/v4/net"
  6. )
  7. func GetTCPCount() (int, error) {
  8. stats, err := net.Connections("tcp")
  9. if err != nil {
  10. return 0, err
  11. }
  12. return len(stats), nil
  13. }
  14. func GetUDPCount() (int, error) {
  15. stats, err := net.Connections("udp")
  16. if err != nil {
  17. return 0, err
  18. }
  19. return len(stats), nil
  20. }