Goroutines. Goroutines everywhere.
This commit is contained in:
parent
574a1af11a
commit
ae7734248d
29
main.go
29
main.go
|
@ -25,6 +25,7 @@ import (
|
|||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
@ -39,17 +40,32 @@ type WifiClient struct {
|
|||
Packets int64
|
||||
}
|
||||
|
||||
const CSVDumps = `/home/konrad/go/src/git.kolaente.de/konrad/wifi-statistics`
|
||||
const TheClientCSVHeader = `Station MAC, First time seen, Last time seen, Power, # packets, BSSID, Probed ESSIDs`
|
||||
const CSVDumps = `/home/konrad/go/src/git.kolaente.de/sofaraum/client`
|
||||
const SecondsUntilInactive = 120
|
||||
const UpdateSecondsInterval = 2
|
||||
const WifiInterface = `wlp59s0`
|
||||
|
||||
func main() {
|
||||
|
||||
stop := make(chan int)
|
||||
go func() {
|
||||
err := exec.Command("/bin/bash", []string{"-c", "airodump-ng " + WifiInterface + " -w " + CSVDumps + "/dump --output-format csv"}...).Run()
|
||||
if err != nil {
|
||||
log.Println("Could not run airodump-ng. Please make sure it is installed and you have sufficent permissions. ", err)
|
||||
stop <- 1
|
||||
}
|
||||
}()
|
||||
|
||||
go func() {
|
||||
for {
|
||||
time.Sleep(UpdateSecondsInterval * time.Second)
|
||||
|
||||
clients := ParseCSVDumps(CSVDumps)
|
||||
|
||||
var activeClients int64
|
||||
for _, c := range clients {
|
||||
fmt.Println(fmt.Sprintf("Mac: %s | First seen: %s | Last seen: %s | Power: %d | Packets: %d | Active: %t", c.MACAdress, c.FirstSeen.String(), c.LastSeen.String(), c.Power, c.Packets, c.isActive()))
|
||||
//fmt.Println(fmt.Sprintf("Mac: %s | First seen: %s | Last seen: %s | Power: %d | Packets: %d | Active: %t", c.MACAdress, c.FirstSeen.String(), c.LastSeen.String(), c.Power, c.Packets, c.isActive()))
|
||||
if c.isActive() {
|
||||
activeClients++
|
||||
}
|
||||
|
@ -57,6 +73,15 @@ func main() {
|
|||
fmt.Println("Active Clients:", activeClients)
|
||||
fmt.Println("Total Clients:", len(clients))
|
||||
}
|
||||
}()
|
||||
|
||||
for exit := range stop {
|
||||
if exit == 0 {
|
||||
continue
|
||||
}
|
||||
os.Exit(exit)
|
||||
}
|
||||
}
|
||||
|
||||
func ParseCSVDumps(pathToDumps string) (clients []*WifiClient) {
|
||||
err := filepath.Walk(pathToDumps, func(dumpPath string, info os.FileInfo, err error) error {
|
||||
|
|
Loading…
Reference in New Issue