工具链接
效果
源码
package main
import (
"fmt"
"golang.org/x/text/encoding/simplifiedchinese"
"os/exec"
"strings"
)
type Charset string
const (
UTF8 = Charset("UTF-8")
GB18030 = Charset("GB18030")
)
func main() {
defer func() {
err := recover()
if err!=nil {
fmt.Println(err)
}
}()
fmt.Println("正在查询wlan")
command := exec.Command("cmd","/C", "netsh wlan show profile")
output, err := command.Output()
if err != nil {
fmt.Println("执行失败")
}
byte2String := ConvertByte2String(output, "GB18030")
any := strings.Index(byte2String, "所有用户配置文件")
s := byte2String[any:]
s = strings.TrimSpace(s)
split := strings.Split(s, "\n")
var list [20]string
flag:=true
for flag {
for i, s2 := range split {
space := strings.TrimSpace(s2)
s3 := strings.TrimSpace(strings.Split(space, ":")[1])
fmt.Println(i," ",s3)
list[i]=s3
}
var idx int
fmt.Println("请输入你想查询的wifi编号: ")
fmt.Scanln(&idx)
fmt.Println("正在查询请稍候... ")
cmd:="netsh wlan show profile name="+list[idx]+" key=clear"
c := exec.Command("cmd", "/C", cmd)
out, err := c.Output()
if err != nil {
fmt.Println("查询失败")
}
str := ConvertByte2String(out,"GB18030")
contains := strings.Contains(str, "关键内容")
if !contains {
fmt.Println("密码不存在,请选择其它wifi查询")
continue
}
index := strings.Index(str, "关键内容")
str = str[index:]
str = strings.Split(str, "\n")[0]
str = strings.Split(str, ": ")[1]
fmt.Println()
fmt.Println("***密码为: ",str)
fmt.Println()
fmt.Println("是否退出? 1:退出 2:继续查询")
var exitFlag int
fmt.Scanln(&exitFlag)
if exitFlag == 1 {
flag = false
continue
}
flag = true
}
}
//字节转str
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
}
CMD查看
- win+R cmd
- netsh wlan show profile
- netsh wlan show profile name=wifi名称 key=clear