Signed-off-by: Hadi <[email protected]>
This commit is contained in:
Hadi
2026-08-13 00:58:37 +02:00
commit 59b31e5ca3
103 changed files with 8577 additions and 0 deletions
+45
View File
@@ -0,0 +1,45 @@
package network
// EthernetDevice is a wired network interface and its active profile, if any.
type EthernetDevice struct {
Device string
Connection string
State string
IP4 string
}
func (e EthernetDevice) Connected() bool {
return e.State == "connected"
}
// ListEthernet returns every ethernet device, with its private IPv4 address
// filled in when connected.
func ListEthernet() ([]EthernetDevice, error) {
devices, err := ListDevices()
if err != nil {
return nil, err
}
eth := make([]EthernetDevice, 0)
for _, d := range devices {
if d.Type != "ethernet" {
continue
}
e := EthernetDevice{
Device: d.Name,
Connection: d.Connection,
State: d.State,
}
if e.Connected() {
e.IP4, _ = DeviceIP4(d.Name)
}
eth = append(eth, e)
}
return eth, nil
}
// EthernetDown deactivates an ethernet device.
func EthernetDown(device string) error {
_, err := run("device", "disconnect", device)
return err
}