This repository has been archived on 2025-03-19. You can view files and clone it, but cannot push or open issues or pull requests.
gonetworkmanager/examples/devices/devices.go
Christian Müller 8fe336a60b Update to v2
2022-11-22 11:30:00 +01:00

38 lines
660 B
Go

package main
import (
"fmt"
"github.com/Wifx/gonetworkmanager/v2"
"os"
)
func main() {
/* Create new instance of gonetworkmanager */
nm, err := gonetworkmanager.NewNetworkManager()
if err != nil {
fmt.Println(err.Error())
os.Exit(1)
}
/* Get devices */
devices, err := nm.GetPropertyAllDevices()
if err != nil {
fmt.Println(err.Error())
os.Exit(1)
}
/* Show each device path and interface name */
for _, device := range devices {
deviceInterface, err := device.GetPropertyInterface()
if err != nil {
fmt.Println(err.Error())
continue
}
fmt.Println(deviceInterface + " - " + string(device.GetPath()))
}
os.Exit(0)
}