ZT-CLI member's info

Hey,

I was looking to have a member list, same as shown in portal, under a network via CLI.
meaning to be able to get all IPs that are members of my private subnet, maybe with the Metadata (description) I added, when I used the GUI dashboard, but via ZT-CLI.

my workaround was IP scanner… but it is not enough, since I had no hostnames and description, and could not figure who is who :sunny:

Thanks

The best way I can think to do this is to use the ZeroTier Central API.

You can go to this link for instructions: ZeroTier Central API | ZeroTier Documentation</title

You’ll need to create an API token in your accounts section. Here’s a quick Python script you can run from your node (can actually be run from any node) to list all of the peers and their IPs:

import requests
import json

# Replace 'insert_zerotier_central_api_token' with your actual token
token = 'insert_zerotier_central_api_token'

# Define the API endpoint URL; replace insert_network_id with your network id
url = 'https://api.zerotier.com/api/v1/network/insert_network_id/member'

# Create headers with the Authorization token
headers = {
    'Authorization': f'token {token}'
}

# Send the GET request
response = requests.get(url, headers=headers)

# Check the response status code
if response.status_code == 200:
    # Request was successful, you can access the response content
    network_data = response.json()
    for i in network_data:
        print(f"{i['config']['address']} {i['config']['ipAssignments']}")
else:
    # Request failed, handle the error
    print(f"Failed to retrieve data. Status code: {response.status_code}")

I wrote a Contextual CLI here: ZT Contextual CLI - #2 by l0crian

I can make an update to it for something like “show peers detail” and it could reach out to the ZeroTier Central API to get more information.

Here’s an update to my CLI Script. Is this along the lines of the output you would like to see?:

Script Output
ZeroTier-> show peers
200 listpeers <ztaddr> <path> <latency> <version> <role>
200 listpeers 0123456789 127.0.0.1/9993;178;174 3 1.10.3 LEAF
200 listpeers 0123456789 127.0.0.2/21041;794;8264 56 1.12.2 LEAF
200 listpeers 0123456789 127.0.0.3/9993;5440;192222 -1 - PLANET
200 listpeers 0123456789 127.0.0.4/9993;178;28248 56 - PLANET
200 listpeers 0123456789 127.0.0.5/9993;1222;3484 2 1.12.2 LEAF
200 listpeers 0123456789 127.0.0.6/9993;5440;192494 -1 - PLANET
200 listpeers 0123456789 127.0.0.7/9993;5440;192586 -1 - PLANET
200 listpeers 0123456789 127.0.0.8/9993;1220;3246 2 1.12.2 LEAF
200 listpeers 0123456789 127.0.0.9/9993;1216;3244 1 1.12.2 LEAF

ZeroTier-> show peers details
| Name   | NodeID     | IP                 | Network          | Version   |
|--------|------------|--------------------|------------------|-----------|
| Name1  | 0123456789 | ['10.100.200.1']   | 0123456789abcdef | 1.10.3    |
| Name2  | 0123456789 | ['10.100.200.2']   | 0123456789abcdef | 1.12.2    |
| Name3  | 0123456789 | ['10.100.200.3']   | 0123456789abcdef | 1.12.2    |
| Name4  | 0123456789 | ['10.100.200.4']   | 0123456789abcdef | 1.12.2    |
| Name4  | 0123456789 | ['10.100.250.4']   | fedcba9876543210 | 1.12.2    |
Script

GitHub - l0crian1/ztcli: Contextual CLI for ZeroTier written in Python

Place the script in the zerotier-one folder as a python file. Run it with python3.

Hi
Thanks for the reply, unfortunately I am not familiar (yet) with Python and was looking a build in CLI command/parameter.
Maybe it belongs to new feature request :slight_smile:

Br
Ronen

There’s no built in command for this. The data you’re asking for isn’t known at the clients themselves. It’s only known by the network controller, so it’s not possible to retrieve from the client alone. You’ll have to incorporate some API calls to https://my.zerotier.com (or your self hosted controller) in order to get the member information

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.