(gather-network {:keys [exec shell]})Gathers hostname, network interface, default gateway and DNS
configuration facts from the host reachable via exec.
Takes a map with:
:exec - an executor function that runs a script string on the
target host and returns {:exit int :out string :err string}.:shell - the shell map returned by eyre.shell/gather-shell;
its :type selects which embedded collection script is run.
Shells without a specific script fall back to the POSIX script.A map with:
:hostname - the system hostname string.:interfaces - a map of interface name -> interface map (see
below).:default-gateway - {:address :interface} for the default
route, or nil when there is none.:dns - {:nameservers ["8.8.8.8" ...] :search ["example.com" ...]}.Each :interfaces value has:
:name - interface name (matches the map key).:mac - normalized MAC address string, or nil.:mtu - MTU in bytes, or nil.:status - :up, :down or :unknown.:loopback? - true for the loopback interface.:ipv4 / :ipv6 - vectors of {:address :prefix} maps, e.g.
{:address "10.0.0.5" :prefix 24}.On unix the source is, in order of preference, ip -o (iproute2),
ifconfig, or the /proc and /sys filesystems; the gateway comes
from ip route, netstat -rn or /proc/net/route, and DNS from
/etc/resolv.conf or scutil --dns on macOS. On Windows the data
comes from Get-Net* PowerShell cmdlets or netsh/ipconfig/
route print under :cmd-exe.
(network/gather-network {:exec local-exec :shell shell})
;; => {:hostname "myhost"
;; :interfaces {"eth0" {:name "eth0" :mac "aa:bb:cc:dd:ee:ff"
;; :mtu 1500 :status :up :loopback? false
;; :ipv4 [{:address "10.0.0.5" :prefix 24}]
;; :ipv6 []}}
;; :default-gateway {:address "10.0.0.1" :interface "eth0"}
;; :dns {:nameservers ["8.8.8.8"] :search ["example.com"]}}
Gathers hostname, network interface, default gateway and DNS
configuration facts from the host reachable via `exec`.
## Arguments
Takes a map with:
- `:exec` - an executor function that runs a script string on the
target host and returns `{:exit int :out string :err string}`.
- `:shell` - the shell map returned by `eyre.shell/gather-shell`;
its `:type` selects which embedded collection script is run.
Shells without a specific script fall back to the POSIX script.
## Returns
A map with:
- `:hostname` - the system hostname string.
- `:interfaces` - a map of interface name -> interface map (see
below).
- `:default-gateway` - `{:address :interface}` for the default
route, or `nil` when there is none.
- `:dns` - `{:nameservers ["8.8.8.8" ...] :search ["example.com"
...]}`.
Each `:interfaces` value has:
- `:name` - interface name (matches the map key).
- `:mac` - normalized MAC address string, or `nil`.
- `:mtu` - MTU in bytes, or `nil`.
- `:status` - `:up`, `:down` or `:unknown`.
- `:loopback?` - true for the loopback interface.
- `:ipv4` / `:ipv6` - vectors of `{:address :prefix}` maps, e.g.
`{:address "10.0.0.5" :prefix 24}`.
On unix the source is, in order of preference, `ip -o` (iproute2),
`ifconfig`, or the `/proc` and `/sys` filesystems; the gateway comes
from `ip route`, `netstat -rn` or `/proc/net/route`, and DNS from
`/etc/resolv.conf` or `scutil --dns` on macOS. On Windows the data
comes from `Get-Net*` PowerShell cmdlets or `netsh`/`ipconfig`/
`route print` under `:cmd-exe`.
## Example
```clojure
(network/gather-network {:exec local-exec :shell shell})
;; => {:hostname "myhost"
;; :interfaces {"eth0" {:name "eth0" :mac "aa:bb:cc:dd:ee:ff"
;; :mtu 1500 :status :up :loopback? false
;; :ipv4 [{:address "10.0.0.5" :prefix 24}]
;; :ipv6 []}}
;; :default-gateway {:address "10.0.0.1" :interface "eth0"}
;; :dns {:nameservers ["8.8.8.8"] :search ["example.com"]}}
```(gather-script shell-type)Returns the embedded collection script for shell-type. Falls back
to the POSIX script when no specific script is available.
Returns the embedded collection script for `shell-type`. Falls back to the POSIX script when no specific script is available.
(process-network shell-type sections)Processes parsed network collection sections into a network facts map.
Processes parsed network collection sections into a network facts map.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |