Package wpaclient provides a high level wap_supplicant client.
go get github.com/brlbil/wpaclient
Client can execute commands, all of the available commands are exported.
// Initialize n new client
client, err := New("wlan0")
if err != nil {
return err
}
// Close connection
defer client.Close()
// Execute a command, all commands are exported
buf, err := client.Execute(CmdPing)
fmt.Println(buf)
$ PONG
Scan is a helper function for SCAN and SCAN_RESULTS commands.
aps, err := client.Scan()
for _, ap := range aps {
fmt.Printf("ssid: %s mac: %s freq: %d signal strength: %d\n",
ap.SSID, ap.BSSID, ap.Frequency, ap.SignalStrength)
}
List is a helper function for LIST_NETWORKS command.
nets, err := client.Networks()
for _, nt := range nets {
fmt.Printf("id: %d, ssid: %s\n", nt.ID, nt.SSID)
}
Client get event notification by opening a second socket connection.
// Get all events
ch, err := client.Notify()
// Just get connection and disconnection events.
ch, err := client.Notify(WpaEventConnected, WpaEventDisconnected)
ev := <- ch
The MIT License (MIT) - see LICENSE.md
for more details