-
Notifications
You must be signed in to change notification settings - Fork 4
/
parsers.go
61 lines (58 loc) · 1.45 KB
/
parsers.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
package main
import (
"bufio"
"log"
"os"
"regexp"
"strings"
)
//filterBSSID returns all GPSXMLPoint structs that have a particular bssid field
func filterBSSID(points Points, bssid []string, filter *int) (filteredPoints Points) {
for _, i := range points {
for _, n := range bssid {
if i.BSSID == n {
if *filter > 0 && (i.Dbm*-1) < *filter {
filteredPoints = append(filteredPoints, i)
} else {
filteredPoints = append(filteredPoints, i)
}
}
}
}
if len(filteredPoints) == 0 {
log.Fatal("Your BSSID was not found in the file")
}
return
}
//parseBssid takes a filename or comma seperated list of BSSIDs
//and outputs an array containing the parsed BSSIDs
func parseBssid(bssids *string) []string {
var (
bssidSlice []string
tempBssidSlice []string
)
r, err := regexp.Compile("(([a-zA-Z0-9]{2}:)){5}[a-zA-Z0-9]{2}")
checkError(err)
file, err := os.Open(*bssids)
if err == nil {
defer file.Close()
var lines []string
scanner := bufio.NewScanner(file)
scanner.Split(bufio.ScanLines)
for scanner.Scan() {
lines = append(lines, scanner.Text())
}
bssidSlice = lines
} else {
bssidSlice = strings.Split(*bssids, ",")
}
for i := 0; i < len(bssidSlice); i++ {
if r.MatchString(bssidSlice[i]) {
tempBssidSlice = append(tempBssidSlice, strings.ToUpper(bssidSlice[i]))
}
}
if len(tempBssidSlice) == 0 {
log.Fatal("Looks like you didn't have any correctly formatted SSIDs")
}
return tempBssidSlice
}