built the shit
This commit is contained in:
parent
7d5c826dba
commit
a9a48ffbd8
103
main.go
103
main.go
|
@ -6,43 +6,100 @@ import (
|
||||||
"encoding/csv"
|
"encoding/csv"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"log"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
type WifiClient struct {
|
||||||
const TheClientCSVHeader = `Station MAC, First time seen, Last time seen, Power, # packets, BSSID, Probed ESSIDs`
|
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 {
|
if err != nil {
|
||||||
panic(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
all := string(bs)
|
all := string(bs)
|
||||||
i := 0
|
i := 0
|
||||||
i = strings.Index(all, TheClientCSVHeader)
|
i = strings.Index(all, TheClientCSVHeader)
|
||||||
arefun := all[i+len(TheClientCSVHeader)+2:]
|
arefun := all[i+len(TheClientCSVHeader)+1:]
|
||||||
//fmt.Println(arefun)
|
arefun = strings.Replace(arefun, " ", "", -1)
|
||||||
|
|
||||||
scanner := bufio.NewScanner(strings.NewReader(arefun))
|
scanner := bufio.NewScanner(strings.NewReader(arefun))
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
fmt.Println(scanner.Text())
|
|
||||||
r := csv.NewReader(bytes.NewReader(scanner.Bytes()))
|
r := csv.NewReader(bytes.NewReader(scanner.Bytes()))
|
||||||
for {
|
record, err := r.Read()
|
||||||
record, err := r.Read()
|
if err != nil {
|
||||||
|
if err.Error() == "EOF" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
power, err := strconv.ParseInt(record[3], 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
red := bytes.NewReader([]byte(arefun))
|
}
|
||||||
r := csv.NewReader(red)
|
|
||||||
for {
|
func parseDateToUnix(date string) (unix time.Time) {
|
||||||
record, err := r.Read()
|
unix, err := time.Parse("2006-01-0215:04:05", date)
|
||||||
if err == io.EOF {
|
if err != nil {
|
||||||
break
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
if err != nil {
|
return
|
||||||
log.Fatal(err)
|
}
|
||||||
}
|
|
||||||
|
func (c *WifiClient) isActive() bool {
|
||||||
fmt.Println(record)
|
// 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