networks.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. * Copyright (c)2013-2020 ZeroTier, Inc.
  3. *
  4. * Use of this software is governed by the Business Source License included
  5. * in the LICENSE.TXT file in the project's root directory.
  6. *
  7. * Change Date: 2024-01-01
  8. *
  9. * On the date above, in accordance with the Business Source License, use
  10. * of this software will be governed by version 2.0 of the Apache License.
  11. */
  12. /****/
  13. package cli
  14. import (
  15. "fmt"
  16. "os"
  17. "zerotier/pkg/zerotier"
  18. )
  19. func Networks(basePath, authToken string, args []string, jsonOutput bool) {
  20. var networks []zerotier.APINetwork
  21. apiGet(basePath, authToken, "/network", &networks)
  22. if jsonOutput {
  23. fmt.Println(jsonDump(networks))
  24. } else {
  25. fmt.Printf("%-16s %-24s %-17s %-8s <type> <device> <managed IP(s)>\n", "<id>", "<name>", "<mac>", "<status>")
  26. for _, nw := range networks {
  27. t := "PRIVATE"
  28. if nw.Config.Type == zerotier.NetworkTypePublic {
  29. t = "PUBLIC"
  30. }
  31. fmt.Printf("%.16x %-24s %-17s %-16s %-7s %-16s ", uint64(nw.ID), nw.Config.Name, nw.Config.MAC.String(), networkStatusStr(nw.Config.Status), t, nw.PortName)
  32. for i, ip := range nw.Config.AssignedAddresses {
  33. if i > 0 {
  34. fmt.Print(",")
  35. }
  36. fmt.Print(ip.String())
  37. }
  38. fmt.Print("\n")
  39. }
  40. }
  41. os.Exit(0)
  42. }