-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.go
80 lines (74 loc) · 1.54 KB
/
main.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
68
69
70
71
72
73
74
75
76
77
78
79
80
package main
import (
"bufio"
"fmt"
"golang.org/x/text/encoding/simplifiedchinese"
"os/exec"
"strings"
)
type Charset string
const (
UTF8 = Charset("UTF-8")
GB18030 = Charset("GB18030")
)
func main() {
command := "netsh"
params := []string{"wlan","show","profiles"}
cmd := exec.Command(command, params...)
stdout, err := cmd.StdoutPipe()
if err != nil {
fmt.Println(err)
return
}
cmd.Start()
in := bufio.NewScanner(stdout)
count := 0
for in.Scan() {
cmdRe:=ConvertByte2String(in.Bytes(),"GB18030")
if strings.Contains(cmdRe,"所有用户配置文件") {
count++
index := strings.Index(cmdRe,":")
getKey(cmdRe[index+2:])
}
}
cmd.Wait()
if count == 0 {
fmt.Println("此电脑未连过wifi")
}
fmt.Scanf("按任意键结束")
}
func getKey(name string) {
command := "netsh"
params := []string{"wlan","show","profiles","name=",name,"key=clear"}
cmd := exec.Command(command, params...)
stdout, err := cmd.StdoutPipe()
if err != nil {
fmt.Println(err)
return
}
cmd.Start()
in := bufio.NewScanner(stdout)
for in.Scan() {
cmdRe:=ConvertByte2String(in.Bytes(),"GB18030")
if strings.Contains(cmdRe,"关键内容") {
index := strings.Index(cmdRe,":")
st := cmdRe[index+2:]
fmt.Println(name,":",st)
}
}
cmd.Wait()
return
}
func ConvertByte2String(byte []byte, charset Charset) string {
var str string
switch charset {
case GB18030:
var decodeBytes,_=simplifiedchinese.GB18030.NewDecoder().Bytes(byte)
str= string(decodeBytes)
case UTF8:
fallthrough
default:
str = string(byte)
}
return str
}