forked from theojulienne/go-wireless
-
Notifications
You must be signed in to change notification settings - Fork 0
/
state.go
56 lines (51 loc) · 1.28 KB
/
state.go
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package wireless
import "strings"
// State represents the current status of WPA
type State struct {
BSSID string `json:"bssid"`
SSID string `json:"ssid"`
ID string `json:"id"`
Mode string `json:"mode"`
KeyManagement string `json:"key_management"`
WpaState string `json:"wpa_state"`
IPAddress string `json:"ip_address"`
Address string `json:"address"`
UUID string `json:"uuid"`
GroupCipher string `json:"group_cipher"`
PairwiseCipher string `json:"pairwise_cipher"`
}
// NewState will return the state of the WPA when given the raw output
func NewState(data string) State {
s := State{}
for _, l := range strings.Split(data, "\n") {
bits := strings.Split(strings.TrimSpace(l), "=")
if len(bits) < 2 {
continue
}
switch bits[0] {
case "bssid":
s.BSSID = bits[1]
case "ssid":
s.SSID = bits[1]
case "id":
s.ID = bits[1]
case "mode":
s.Mode = bits[1]
case "key_management":
s.KeyManagement = bits[1]
case "wpa_state":
s.WpaState = bits[1]
case "ip_address":
s.IPAddress = bits[1]
case "address":
s.Address = bits[1]
case "uuid":
s.UUID = bits[1]
case "group_cipher":
s.GroupCipher = bits[1]
case "pairwise_cipher":
s.PairwiseCipher = bits[1]
}
}
return s
}