mirror of
https://github.com/ZeroTier/ZeroTierOne
synced 2025-08-21 05:43:59 -07:00
.
This commit is contained in:
parent
5175636d36
commit
7061f13b24
10 changed files with 229 additions and 43 deletions
|
@ -13,6 +13,51 @@
|
|||
|
||||
package cli
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"zerotier/pkg/zerotier"
|
||||
)
|
||||
|
||||
// Peers CLI command
|
||||
func Peers(basePath, authToken string, args []string) {
|
||||
func Peers(basePath, authToken string, args []string, jsonOutput bool) {
|
||||
var peers []zerotier.Peer
|
||||
apiGet(basePath, authToken, "/peer", &peers)
|
||||
|
||||
if jsonOutput {
|
||||
j, _ := json.MarshalIndent(&peers, "", " ")
|
||||
fmt.Println(string(j))
|
||||
} else {
|
||||
fmt.Printf("<ztaddr> <ver> <role> <lat> <link> <lastTX> <lastRX> <path(s)>\n")
|
||||
for _, peer := range peers {
|
||||
role := "LEAF"
|
||||
link := "RELAY"
|
||||
lastTX, lastRX := int64(0), int64(0)
|
||||
address := ""
|
||||
if len(peer.Paths) > 0 {
|
||||
link = "DIRECT"
|
||||
lastTX, lastRX = peer.Clock-peer.Paths[0].LastSend, peer.Clock-peer.Paths[0].LastReceive
|
||||
if lastTX < 0 {
|
||||
lastTX = 0
|
||||
}
|
||||
if lastRX < 0 {
|
||||
lastRX = 0
|
||||
}
|
||||
address = fmt.Sprintf("%s/%d", peer.Paths[0].IP.String(), peer.Paths[0].Port)
|
||||
}
|
||||
fmt.Printf("%.10x %-7s %-6s %-5d %-6s %-8d %-8d %s\n",
|
||||
uint64(peer.Address),
|
||||
fmt.Sprintf("%d.%d.%d", peer.Version[0], peer.Version[1], peer.Version[2]),
|
||||
role,
|
||||
peer.Latency,
|
||||
link,
|
||||
lastTX,
|
||||
lastRX,
|
||||
address,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
os.Exit(0)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue