forked from kurokirasama/nushell_scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget-ips.nu
More file actions
26 lines (21 loc) · 660 Bytes
/
get-ips.nu
File metadata and controls
26 lines (21 loc) · 660 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/usr/bin/env nu
export def main [
...hosts #list of hosts
] {
let host = sys host | get hostname
let device = if ($host like $hosts.2) or ($host like $hosts.8) {
sys net | where name =~ '^en' | get name.0
} else {
sys net | where name =~ '^wl' | get name.0
}
let internal = ip -json add
| from json
| where ifname like $device
| select addr_info
| flatten | find -v inet6
| flatten
| get local
| get 0
let external = dig +short myip.opendns.com @resolver1.opendns.com
return ({internal: $internal, external: $external} | to json)
}