diff --git a/main.go b/main.go index 9ea50ae..5b7787d 100644 --- a/main.go +++ b/main.go @@ -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) {