lan.go 571 B

1234567891011121314151617181920212223242526272829
  1. // Copyright (C) 2015 The Syncthing Authors.
  2. //
  3. // This Source Code Form is subject to the terms of the Mozilla Public
  4. // License, v. 2.0. If a copy of the MPL was not distributed with this file,
  5. // You can obtain one at https://mozilla.org/MPL/2.0/.
  6. package osutil
  7. import (
  8. "net"
  9. )
  10. func GetLans() ([]*net.IPNet, error) {
  11. addrs, err := net.InterfaceAddrs()
  12. if err != nil {
  13. return nil, err
  14. }
  15. nets := make([]*net.IPNet, 0, len(addrs))
  16. for _, addr := range addrs {
  17. net, ok := addr.(*net.IPNet)
  18. if ok {
  19. nets = append(nets, net)
  20. }
  21. }
  22. return nets, nil
  23. }