built the shit
This commit is contained in:
parent
7d5c826dba
commit
a9a48ffbd8
93
main.go
93
main.go
|
@ -6,43 +6,100 @@ import (
|
|||
"encoding/csv"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
const TheClientCSVHeader = `Station MAC, First time seen, Last time seen, Power, # packets, BSSID, Probed ESSIDs`
|
||||
type WifiClient struct {
|
||||
MACAdress string
|
||||
FirstSeen time.Time
|
||||
LastSeen time.Time
|
||||
Power int64
|
||||
Packets int64
|
||||
}
|
||||
|
||||
bs, err := ioutil.ReadFile("dump.csv")
|
||||
const CSVDump = `dump.csv`
|
||||
const TheClientCSVHeader = `Station MAC, First time seen, Last time seen, Power, # packets, BSSID, Probed ESSIDs`
|
||||
const SecondsUntilInactive = 120
|
||||
|
||||
func main() {
|
||||
|
||||
clients := ParseCSVDump(CSVDump)
|
||||
|
||||
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))
|
||||
}
|
||||
|
||||
func ParseCSVDump(pathToDump string) (clients []*WifiClient) {
|
||||
bs, err := ioutil.ReadFile(pathToDump)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal(err)
|
||||
}
|
||||
all := string(bs)
|
||||
i := 0
|
||||
i = strings.Index(all, TheClientCSVHeader)
|
||||
arefun := all[i+len(TheClientCSVHeader)+2:]
|
||||
//fmt.Println(arefun)
|
||||
arefun := all[i+len(TheClientCSVHeader)+1:]
|
||||
arefun = strings.Replace(arefun, " ", "", -1)
|
||||
|
||||
scanner := bufio.NewScanner(strings.NewReader(arefun))
|
||||
for scanner.Scan() {
|
||||
fmt.Println(scanner.Text())
|
||||
r := csv.NewReader(bytes.NewReader(scanner.Bytes()))
|
||||
for {
|
||||
record, err := r.Read()
|
||||
if err != nil {
|
||||
if err.Error() == "EOF" {
|
||||
continue
|
||||
}
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
/*
|
||||
red := bytes.NewReader([]byte(arefun))
|
||||
r := csv.NewReader(red)
|
||||
for {
|
||||
record, err := r.Read()
|
||||
if err == io.EOF {
|
||||
break
|
||||
}
|
||||
power, err := strconv.ParseInt(record[3], 10, 64)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
fmt.Println(record)
|
||||
}*/
|
||||
packets, err := strconv.ParseInt(record[4], 10, 64)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
clients = append(clients, &WifiClient{
|
||||
MACAdress: record[0],
|
||||
FirstSeen: parseDateToUnix(record[1]),
|
||||
LastSeen: parseDateToUnix(record[2]),
|
||||
Power: power,
|
||||
Packets: packets,
|
||||
})
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func parseDateToUnix(date string) (unix time.Time) {
|
||||
unix, err := time.Parse("2006-01-0215:04:05", date)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (c *WifiClient) isActive() bool {
|
||||
// Should normally not be set here, should take the system time -> see below
|
||||
current := time.Date(2018, 11, 14, 14, 31, 0, 0, &time.Location{})
|
||||
diff := current.Sub(c.LastSeen)
|
||||
|
||||
//diff := time.Since(c.LastSeen)
|
||||
if diff < SecondsUntilInactive*time.Second {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue