-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscanners_darwin.go
67 lines (54 loc) · 1.43 KB
/
scanners_darwin.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
57
58
59
60
61
62
63
64
65
66
67
package main
import (
"encoding/json"
"encoding/xml"
"os/exec"
)
type SystemProfilerBluetooth struct {
SPBluetoothDataType []struct {
DeviceConnected []map[string]struct {
DeviceAddress string `json:"device_address"`
} `json:"device_connected"`
} `json:"SPBluetoothDataType"`
}
func scanBluetoothDevices() ([]string, error) {
devices := []string{}
cmd := exec.Command("system_profiler", "-json", "SPBluetoothDataType")
output, err := cmd.Output()
if err != nil {
return devices, err
}
var spBluetooth SystemProfilerBluetooth
err = json.Unmarshal(output, &spBluetooth)
if err != nil {
return devices, err
}
for _, deviceConnected := range spBluetooth.SPBluetoothDataType[0].DeviceConnected {
for _, device := range deviceConnected {
devices = append(devices, device.DeviceAddress)
}
}
return devices, nil
}
type WifiScanResult struct {
Networks []struct {
IE string `xml:"IE"`
} `xml:"array>dict"`
}
func scanWifiNetworks() ([]string, error) {
networks := []string{}
cmd := exec.Command("/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport", "-s", "--xml")
output, err := cmd.Output()
if err != nil {
return networks, err
}
var wifiScanResult WifiScanResult
err = xml.Unmarshal(output, &wifiScanResult)
if err != nil {
return networks, err
}
for _, network := range wifiScanResult.Networks {
networks = append(networks, network.IE)
}
return networks, nil
}