Created
February 18, 2024 17:30
-
-
Save rcoder/78e113fa0a99aa668424286e03c40500 to your computer and use it in GitHub Desktop.
General `/etc/hosts` file for ZeroTier Central networks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const API_BASE = "https://api.zerotier.com/api/v1" | |
let token = $env.ZT_TOKEN | |
let headers = { | |
Authorization: $"token ($token)" | |
} | |
def apiGet [path: string] { | |
http get --headers $headers $"($API_BASE)/($path)" | |
} | |
def main [] { | |
(apiGet "network") | each {|network| | |
print $"# ($network.config.name): ($network.id)" | |
(apiGet $"network/($network.id)/member") | each {|member| | |
if $member.name != "" { | |
let hostname = $"($member.name).($network.config.name).zt" | |
let comment = $"# ($member.name): ($member.nodeId)" | |
print $"($member.config.ipAssignments.0)\t($hostname)\t($comment)" | |
} | |
} | |
} | |
null | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment