-
Notifications
You must be signed in to change notification settings - Fork 0
/
output.go
191 lines (182 loc) · 5.98 KB
/
output.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
package main
import (
"encoding/csv"
"github.com/Ramzeth/wifiparser/internal"
"io"
"strconv"
"strings"
)
//ToDO remove
//func outBSSs(db internal.Database,w io.Writer) {
// csvWriter := csv.NewWriter(w)
// defer csvWriter.Flush()
// header := []string{"ESSID", "Description", "BSSID", "AKM", "Encryption", "Channel", "Power", "Manufacturer", "Uptime", "Location", "WPS"}
// csvWriter.Write(header)
// // Output data for non hidden ESS
// for _, ess := range db.Networks {
// writeESSID := ess.ESSID
// tags := make(map[string]bool)
// // Generate description tags
// if len(ess.BSSIDs) > 1 {
// tags["multipleBSS"] = true
// }
// for _,bssid := range ess.BSSIDs {
// writeBSSID := bssid
// ap,ok := db.Accesspoints[bssid]
// // if there is ap for given essid in db
// if ok {
// if len(ap.Setups) > 1 {
// tags["possibleTwin"] = true
// } else {
// delete(tags,"possibleTwin")
// }
// for _,setup := range ap.Setups {
// if setup.ESSID == ess.ESSID {
// writeAKM := setup.AKM
// var encs []string
// for e :=range setup.Encryptions {
// encs = append(encs,e)
// }
// writeEncryption := strings.Join(encs,"/")
// var descriptions []string
// for t := range tags {
// descriptions = append(descriptions,t)
// }
// writeDescription := strings.Join(descriptions,";")
// writeChannel := strconv.Itoa(setup.Channel)
// writePower := strconv.Itoa(setup.Power)
// writeManufacturer := ap.Manufacturer
// writeUptime := parsedTime(setup.Uptime)
// writeLocation := setup.Location
// writeWPS := setup.WPS
// record := []string{writeESSID, writeDescription, writeBSSID, writeAKM, writeEncryption, writeChannel, writePower, writeManufacturer, writeUptime, writeLocation, writeWPS}
// csvWriter.Write(record)
// }
// }
// }
// }
// }
// // Output data for hidden ESS
// for _, ap := range db.Accesspoints {
// tags := make(map[string]bool)
// writeBSSID := ap.BSSID
// for _,setup := range ap.Setups {
// if setup.ESSID == "" {
// writeESSID := setup.ESSID
// writeAKM := setup.AKM
// var encs []string
// for e :=range setup.Encryptions {
// encs = append(encs,e)
// }
// writeEncryption := strings.Join(encs,"/")
// var descriptions []string
// for t := range tags {
// descriptions = append(descriptions,t)
// }
// writeDescription := strings.Join(descriptions,";")
// writeChannel := strconv.Itoa(setup.Channel)
// writePower := strconv.Itoa(setup.Power)
// writeManufacturer := ap.Manufacturer
// writeUptime := parsedTime(setup.Uptime)
// writeLocation := setup.Location
// writeWPS := setup.WPS
// record := []string{writeESSID, writeDescription, writeBSSID, writeAKM, writeEncryption, writeChannel, writePower, writeManufacturer, writeUptime, writeLocation, writeWPS}
// csvWriter.Write(record)
// }
// }
// }
//}
func outESS(db internal.Database, w io.Writer) {
csvWriter := csv.NewWriter(w)
defer csvWriter.Flush()
header := []string{"ESSID", "Anomaly", "Connected ESS", "AKM", "Encryption", "Uptime", "BestPower", "Location", "WPS"}
csvWriter.Write(header)
// Output data for non hidden ESS
essList := db.GetESSIDs()
for _, ess := range essList {
if ess == "" {
continue
}
tagList := db.GetESStags(ess)
setups := db.GetESSsetups(ess)
// Now trying to collapse different setups data for one ess
akmMap := make(map[string]bool)
encMap := make(map[string]bool)
wpsMap := make(map[string]bool)
var maxUptime uint64
bestLocation := ""
bestPower := -1000
for _, s := range setups {
tagList = append(tagList, db.GetBSStags(s.BSSID)...)
akmMap[s.AKM] = true
for e := range s.Encryptions {
encMap[e] = true
}
if s.Uptime > maxUptime {
maxUptime = s.Uptime
}
if s.Power > bestPower {
bestLocation = s.Location
bestPower = s.Power
}
wpsMap[s.WPS] = true
}
var akmList []string
var encList []string
var wpsList []string
for a := range akmMap {
akmList = append(akmList, a)
}
for e := range encMap {
encList = append(encList, e)
}
for w := range wpsMap {
wpsList = append(wpsList, w)
}
// Write ess data
essAnomaly := strings.Join(tagList, ";")
connected := strings.Join(db.GetConnectedESS(ess), "\n")
akm := strings.Join(akmList, "/")
encryption := strings.Join(encList, "/")
wps := strings.Join(wpsList, "/")
record := []string{ess, essAnomaly, connected, akm, encryption, parsedTime(maxUptime), strconv.Itoa(bestPower), bestLocation, wps}
csvWriter.Write(record)
}
}
func outBSS(db internal.Database, w io.Writer) {
csvWriter := csv.NewWriter(w)
defer csvWriter.Flush()
header := []string{"ESSID", "BSSID", "ESS anomaly", "BSS anomaly", "AKM", "Encryption", "Channel", "Power", "Uptime", "Location", "WPS"}
csvWriter.Write(header)
bssids := db.GetBSSIDs()
for _, bssid := range bssids {
for _, setup := range db.GetBSSsetups(bssid) {
var encs []string
for e := range setup.Encryptions {
encs = append(encs, e)
}
writeEncryption := strings.Join(encs, "/")
bssTags := db.GetBSStags(setup.BSSID)
bssAnomaly := strings.Join(bssTags, ";")
essTags := db.GetESStags(setup.ESSID)
essAnomaly := strings.Join(essTags, ";")
record := []string{setup.ESSID, setup.BSSID, essAnomaly, bssAnomaly, setup.AKM, writeEncryption, strconv.Itoa(setup.Channel), strconv.Itoa(setup.Power), parsedTime(setup.Uptime), setup.Location, setup.WPS}
csvWriter.Write(record)
}
}
}
func outRaw(db internal.Database, w io.Writer) {
csvWriter := csv.NewWriter(w)
defer csvWriter.Flush()
header := []string{"ESSID", "BSSID", "AKM", "Encryption", "Channel", "Power", "Uptime", "Location", "WPS"}
csvWriter.Write(header)
for _, r := range db.GetRecords() {
var encs []string
for e := range r.Encryptions {
encs = append(encs, e)
}
writeEncryption := strings.Join(encs, "/")
record := []string{r.ESSID, r.BSSID, r.AKM, writeEncryption, strconv.Itoa(r.Channel), strconv.Itoa(r.Power), parsedTime(r.Uptime), r.Location, r.WPS}
csvWriter.Write(record)
}
}