Goroutines. Goroutines everywhere.
This commit is contained in:
parent
574a1af11a
commit
ae7734248d
45
main.go
45
main.go
|
@ -25,6 +25,7 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -39,23 +40,47 @@ type WifiClient struct {
|
||||||
Packets int64
|
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 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 SecondsUntilInactive = 120
|
||||||
|
const UpdateSecondsInterval = 2
|
||||||
|
const WifiInterface = `wlp59s0`
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
clients := ParseCSVDumps(CSVDumps)
|
stop := make(chan int)
|
||||||
|
go func() {
|
||||||
var activeClients int64
|
err := exec.Command("/bin/bash", []string{"-c", "airodump-ng " + WifiInterface + " -w " + CSVDumps + "/dump --output-format csv"}...).Run()
|
||||||
for _, c := range clients {
|
if err != nil {
|
||||||
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()))
|
log.Println("Could not run airodump-ng. Please make sure it is installed and you have sufficent permissions. ", err)
|
||||||
if c.isActive() {
|
stop <- 1
|
||||||
activeClients++
|
|
||||||
}
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
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) {
|
func ParseCSVDumps(pathToDumps string) (clients []*WifiClient) {
|
||||||
|
|
Loading…
Reference in New Issue