Skip to content

Commit

Permalink
compiled windows darwin
Browse files Browse the repository at this point in the history
  • Loading branch information
TaceyWong committed Nov 4, 2021
1 parent c1c6259 commit e4c3953
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
8 changes: 5 additions & 3 deletions wifipw_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package wifipw

import (
"bytes"
"fmt"
"errors"
"os/exec"
"regexp"
"strings"
)

func WIFIPassword(ssid string) (string, error) {
Expand All @@ -21,10 +23,10 @@ func WIFISSID() (name string, err error) {
cmd := exec.Command("sh", "-c", cmdStr)
cmd.Stdout = &stdout
if err := cmd.Run(); err != nil {
return "", errors.New(stderr.String())
return "", err
}
stdoutStr := stdout.String()
if strings.Contains(stdout, "AirPort: Off") {
if strings.Contains(stdoutStr, "AirPort: Off") {
return "", errors.New("Wi-Fi is turned off")
}
ret := regexp.MustCompile(`^\s*SSID: (.+)\s*$`).FindStringSubmatch(stdout.String())
Expand Down
18 changes: 8 additions & 10 deletions wifipw_windows.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package wifipw

import (
"bytes"
"fmt"
"errors"
"os/exec"
"regexp"
)

func WIFIPassword(ssid string) (string,error) {
output, err := exec.Command("cmd", "/C", "netsh","wlan",
"show","profile","name="+ssid,"key=clear").CombinedOutput()
if err != nil{
return "",err
func WIFIPassword(ssid string) (string, error) {
output, err := exec.Command("cmd", "/C", "netsh", "wlan",
"show", "profile", "name="+ssid, "key=clear").CombinedOutput()
if err != nil {
return "", err
}
ret := regexp.MustCompile(`^\s*Key Content\s*: (.+)\s*$`).FindStringSubmatch(string(output))
if len(ret) < 1 {
Expand All @@ -20,9 +20,7 @@ func WIFIPassword(ssid string) (string,error) {
}

func WIFISSID() (string, error) {
var stdout bytes.Buffer
cmdStr := "netsh wlan show interface"
cmd,err := exec.Command("cmd", "/C", "netsh","wlan","show","interface")..CombinedOutput()
cmd, err := exec.Command("cmd", "/C", "netsh", "wlan", "show", "interface").CombinedOutput()
if err != nil {
return "", err
}
Expand Down

0 comments on commit e4c3953

Please sign in to comment.