forked from shouc/pencake
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwifi_key.go
More file actions
38 lines (34 loc) · 878 Bytes
/
Copy pathwifi_key.go
File metadata and controls
38 lines (34 loc) · 878 Bytes
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
package pencake
import (
"fmt"
"pencake/utils"
"regexp"
)
func WifiKey() []WifiKeyStruct {
switch utils.SystemType() {
case "darwin":
return getMacWifiKey()
default:
utils.NotSupported("")
return []WifiKeyStruct{}
}
}
type WifiKeyStruct struct {
Name string
Password string
}
func getMacWifiKey() []WifiKeyStruct {
wifiSSIDs := utils.RunCommand("defaults read " +
"/Library/Preferences/SystemConfiguration/com.apple.airport.preferences KnownNetworks " +
"| grep 'SSIDString'")
wifiNameRegex := regexp.MustCompile(` {8}SSIDString = (.+?);`)
wifiNames := wifiNameRegex.FindAllStringSubmatch(wifiSSIDs, -1)
var result []WifiKeyStruct
for _, name := range wifiNames {
result = append(result, WifiKeyStruct{
Name: name[1],
Password: utils.RunCommand(fmt.Sprintf("security find-generic-password -wa %s", name[1])),
})
}
return result
}