64 lines
1.5 KiB
Plaintext
64 lines
1.5 KiB
Plaintext
# Get networking info about tailscale peers
|
|
def "tailscale peer" [
|
|
hostname?: string
|
|
get_field?: cell-path
|
|
]: nothing -> any {
|
|
let get_field = ($get_field | 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 $get_field
|
|
}
|
|
}
|
|
|
|
# SSH to a tailscale peer
|
|
def "tailscale ssh" [
|
|
user_hostname: string
|
|
...ssh_flags: string
|
|
]: nothing -> any {
|
|
if "@" in $user_hostname {
|
|
let parsed = ($user_hostname | parse "{user}@{hostname}" | first)
|
|
ssh -o $"HostName (tailscale peer $parsed.hostname | get ipv6)" $user_hostname ...$ssh_flags
|
|
} else {
|
|
ssh -o $"HostName (tailscale peer $user_hostname | get ipv6)" $user_hostname ...$ssh_flags
|
|
}
|
|
}
|
|
|
|
# SCP to a tailscale peer
|
|
def "tailscale scp" [
|
|
from: string
|
|
to: string
|
|
...ssh_flags: string
|
|
]: nothing -> any {
|
|
|
|
let options = (
|
|
[$from, $to] |
|
|
parse "{hostname}:{path}" |
|
|
each { |it| $"HostName (tailscale peer $it.hostname | get ipv6)" } |
|
|
each { |option| ["-o", $option] } |
|
|
flatten
|
|
)
|
|
|
|
scp ...$options $from $to ...$ssh_flags
|
|
}
|