Skip to content

Instantly share code, notes, and snippets.

@rcoder
Created February 18, 2024 17:30
Show Gist options
  • Save rcoder/78e113fa0a99aa668424286e03c40500 to your computer and use it in GitHub Desktop.
Save rcoder/78e113fa0a99aa668424286e03c40500 to your computer and use it in GitHub Desktop.
General `/etc/hosts` file for ZeroTier Central networks
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