mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Display current wifi network name
This commit is contained in:
parent
d82c7692be
commit
42ce7f4353
58
security/client.go
Normal file
58
security/client.go
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
package security
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io/ioutil"
|
||||||
|
"os/exec"
|
||||||
|
"regexp"
|
||||||
|
//"runtime"
|
||||||
|
//"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
const fwGlobalState = "/usr/libexec/ApplicationFirewall/socketfilterfw --getglobalstate"
|
||||||
|
const fwStealthMode = "/usr/libexec/ApplicationFirewall/socketfilterfw --getstealthmode"
|
||||||
|
|
||||||
|
// https://github.com/yelinaung/wifi-name/blob/master/wifi-name.go
|
||||||
|
const osxCmd = "/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport"
|
||||||
|
const osxArgs = "-I"
|
||||||
|
|
||||||
|
func Fetch() map[string]string {
|
||||||
|
data := make(map[string]string)
|
||||||
|
|
||||||
|
data["Wifi"] = WifiName()
|
||||||
|
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
|
||||||
|
func WifiName() string {
|
||||||
|
cmd := exec.Command(osxCmd, osxArgs)
|
||||||
|
|
||||||
|
stdout, err := cmd.StdoutPipe()
|
||||||
|
panicIf(err)
|
||||||
|
|
||||||
|
// start the command after having set up the pipe
|
||||||
|
if err := cmd.Start(); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var str string
|
||||||
|
|
||||||
|
if b, err := ioutil.ReadAll(stdout); err == nil {
|
||||||
|
str += (string(b) + "\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
r := regexp.MustCompile(`s*SSID: (.+)s*`)
|
||||||
|
|
||||||
|
name := r.FindAllStringSubmatch(str, -1)
|
||||||
|
|
||||||
|
if len(name) <= 1 {
|
||||||
|
return ""
|
||||||
|
} else {
|
||||||
|
return name[1][1]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func panicIf(err error) {
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
@ -31,15 +31,14 @@ func NewWidget() *Widget {
|
|||||||
/* -------------------- Exported Functions -------------------- */
|
/* -------------------- Exported Functions -------------------- */
|
||||||
|
|
||||||
func (widget *Widget) Refresh() {
|
func (widget *Widget) Refresh() {
|
||||||
//data := Fetch()
|
data := Fetch()
|
||||||
|
|
||||||
widget.View.SetTitle(" 🐼 Security")
|
widget.View.SetTitle(" 🐼 Security")
|
||||||
widget.RefreshedAt = time.Now()
|
widget.RefreshedAt = time.Now()
|
||||||
|
|
||||||
widget.View.Clear()
|
widget.View.Clear()
|
||||||
|
|
||||||
fmt.Fprintf(widget.View, "%s", "cats and dogs")
|
fmt.Fprintf(widget.View, "%s", widget.contentFrom(data))
|
||||||
//fmt.Fprintf(widget.View, "%s", widget.contentFrom(data))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------- Unexported Functions -------------------- */
|
/* -------------------- Unexported Functions -------------------- */
|
||||||
@ -54,6 +53,16 @@ func (widget *Widget) addView() {
|
|||||||
widget.View = view
|
widget.View = view
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (widget *Widget) contentFrom(data map[string]string) string {
|
||||||
|
str := "\n"
|
||||||
|
|
||||||
|
for key, val := range data {
|
||||||
|
str = str + fmt.Sprintf("%8s: %8s\n", key, val)
|
||||||
|
}
|
||||||
|
|
||||||
|
return str
|
||||||
|
}
|
||||||
|
|
||||||
func (widget *Widget) refresher() {
|
func (widget *Widget) refresher() {
|
||||||
tick := time.NewTicker(time.Duration(widget.RefreshInterval) * time.Second)
|
tick := time.NewTicker(time.Duration(widget.RefreshInterval) * time.Second)
|
||||||
quit := make(chan struct{})
|
quit := make(chan struct{})
|
||||||
|
@ -87,6 +87,8 @@ func icon(data *owm.CurrentWeatherData) string {
|
|||||||
icon = "☁️"
|
icon = "☁️"
|
||||||
case "clear":
|
case "clear":
|
||||||
icon = "☀️"
|
icon = "☀️"
|
||||||
|
case "clear sky":
|
||||||
|
icon = "☀️"
|
||||||
case "cloudy":
|
case "cloudy":
|
||||||
icon = "⛅️"
|
icon = "⛅️"
|
||||||
case "few clouds":
|
case "few clouds":
|
||||||
|
Loading…
x
Reference in New Issue
Block a user