now able to parse multiple csv files at once
This commit is contained in:
parent
9dcf6d9c6f
commit
e2a5d3d6ca
51
main.go
51
main.go
|
@ -7,7 +7,8 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"os/exec"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
@ -21,14 +22,13 @@ type WifiClient struct {
|
||||||
Packets int64
|
Packets int64
|
||||||
}
|
}
|
||||||
|
|
||||||
const CSVDump = `dump.csv`
|
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 SecondsUntilInactive = 120
|
const SecondsUntilInactive = 120
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
clients := ParseCSVDump(CSVDump)
|
clients := ParseCSVDump(CSVDumps)
|
||||||
//clients := GetClientsFromBytes()
|
|
||||||
|
|
||||||
var activeClients int64
|
var activeClients int64
|
||||||
for _, c := range clients {
|
for _, c := range clients {
|
||||||
|
@ -41,36 +41,18 @@ func main() {
|
||||||
fmt.Println("Total Clients:", len(clients))
|
fmt.Println("Total Clients:", len(clients))
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetClientsFromBytes() (clients []*WifiClient) {
|
func ParseCSVDump(pathToDumps string) (clients []*WifiClient) {
|
||||||
|
err := filepath.Walk(pathToDumps, func(dumpPath string, info os.FileInfo, err error) error {
|
||||||
// Tooo much hassle, just output a csv dump and parse that and delete it afterwards should be good enough
|
|
||||||
|
|
||||||
// -u <secs> für delay
|
|
||||||
argstr := []string{"-c", "airodump-ng wlp59s0 -u 9"}
|
|
||||||
command := exec.Command("/bin/bash", argstr...)
|
|
||||||
var buf bytes.Buffer
|
|
||||||
command.Stdout = &buf
|
|
||||||
|
|
||||||
if err := command.Start(); err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
timer := time.AfterFunc(10 *time.Second, func() {
|
|
||||||
err := command.Process.Kill()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
return err
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
command.Wait()
|
|
||||||
timer.Stop()
|
|
||||||
ioutil.WriteFile("dump", buf.Bytes(), 0644)
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func ParseCSVDump(pathToDump string) (clients []*WifiClient) {
|
// Only csv files
|
||||||
bs, err := ioutil.ReadFile(pathToDump)
|
if info.IsDir() || filepath.Ext(dumpPath) != ".csv" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
bs, err := ioutil.ReadFile(dumpPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -110,6 +92,13 @@ func ParseCSVDump(pathToDump string) (clients []*WifiClient) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue