networks.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * Copyright (c)2019 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: 2023-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. // Networks CLI command
  20. func Networks(basePath, authToken string, args []string, jsonOutput bool) {
  21. var networks []zerotier.APINetwork
  22. apiGet(basePath, authToken, "/network", &networks)
  23. if jsonOutput {
  24. fmt.Println(jsonDump(networks))
  25. } else {
  26. fmt.Printf("%-16s %-24s %-17s %-8s <type> <device> <managed IP(s)>\n", "<id>", "<name>", "<mac>", "<status>")
  27. for _, nw := range networks {
  28. t := "PRIVATE"
  29. if nw.Config.Type == zerotier.NetworkTypePublic {
  30. t = "PUBLIC"
  31. }
  32. 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)
  33. for i, ip := range nw.Config.AssignedAddresses {
  34. if i > 0 {
  35. fmt.Print(",")
  36. }
  37. fmt.Print(ip.String())
  38. }
  39. fmt.Print("\n")
  40. }
  41. }
  42. os.Exit(0)
  43. }