Goroutines. Goroutines everywhere.

This commit is contained in:
konrad 2018-11-29 00:20:03 +01:00
parent 574a1af11a
commit ae7734248d
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
1 changed files with 35 additions and 10 deletions

45
main.go
View File

@ -25,6 +25,7 @@ import (
"io/ioutil"
"log"
"os"
"os/exec"
"path/filepath"
"strconv"
"strings"
@ -39,23 +40,47 @@ 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() {
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()))
if c.isActive() {
activeClients++
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()))
if c.isActive() {
activeClients++
}
}
fmt.Println("Active Clients:", activeClients)
fmt.Println("Total Clients:", len(clients))
}
}()
for exit := range stop {
if exit == 0 {
continue
}
os.Exit(exit)
}
fmt.Println("Active Clients:", activeClients)
fmt.Println("Total Clients:", len(clients))
}
func ParseCSVDumps(pathToDumps string) (clients []*WifiClient) {