Add tailscale peer nushell command

This commit is contained in:
2025-05-12 21:37:05 +02:00
parent 9cb3239cfe
commit 7d8410f5ad
2 changed files with 32 additions and 0 deletions

View File

@ -0,0 +1,31 @@
def "tailscale peer" [
hostname?: string
path?: cell-path
]: nothing -> any {
let path = ($path | default ([] | into cell-path))
let status = (^tailscale status --json | from json)
let peers = ($status | get Peer | transpose key fields | flatten fields)
let peers = ($peers | each { |peer|
let ipv4 = $peer.TailscaleIPs | where { |ip| "." in $ip } | first
let ipv6 = $peer.TailscaleIPs | where { |ip| ":" in $ip } | first
{
host: $peer.HostName,
ipv4: $ipv4,
ipv6: $ipv6,
online: $peer.Online,
active: $peer.Active,
rx: ($peer.RxBytes | into filesize),
tx: ($peer.TxBytes | into filesize),
}
})
if $hostname == null {
$peers
} else {
$peers | where host == $hostname | first | get $path
}
}