hwaddr.go 572 B

1234567891011121314151617181920212223242526
  1. // Copyright (c) Tailscale Inc & AUTHORS
  2. // SPDX-License-Identifier: BSD-3-Clause
  3. package posture
  4. import (
  5. "net/netip"
  6. "slices"
  7. "tailscale.com/net/netmon"
  8. )
  9. // GetHardwareAddrs returns the hardware addresses of all non-loopback
  10. // network interfaces.
  11. func GetHardwareAddrs() (hwaddrs []string, err error) {
  12. err = netmon.ForeachInterface(func(i netmon.Interface, _ []netip.Prefix) {
  13. if i.IsLoopback() {
  14. return
  15. }
  16. if a := i.HardwareAddr.String(); a != "" {
  17. hwaddrs = append(hwaddrs, a)
  18. }
  19. })
  20. slices.Sort(hwaddrs)
  21. return slices.Compact(hwaddrs), err
  22. }