-
Notifications
You must be signed in to change notification settings - Fork 0
/
ap_scan
executable file
·121 lines (103 loc) · 2.77 KB
/
ap_scan
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
#!/usr/bin/gawk -f
BEGIN {
now = systime()
out = "/root/ap_scan.out"
stats = "/root/ap_scan.stats"
sort = "sort -nk3"
new = 0
c0 = "\033[0m"
c1 = "\033[0;32m" # green
c2 = "\033[0;33m" # yellow
c3 = "\033[0;31m" # red
c4 = "\033[0;34m" # blue
bold = "\033[0;1m"
while (getline < out) {
days = int((now - $5) / 86400)
hours = int((now - $5 - days * 86400) / 3600)
mins = int((now - $5 - days * 86400 - hours * 3600) / 60 )
name[$1] = $2
channel[$1] = $3
qual[$1] = $4
last[$1] = $5
if (days < 1) {
if (hours < 1) {
if (mins < 1) state[$1] = c1 "< 1 min"
else if (mins < 5) state[$1] = c1 "< 5 min"
else if (mins < 10) state[$1] = c1 "< 10 min"
else if (mins < 30) state[$1] = c1 "< 30 min"
else state[$1] = c1 "< 1 hour"
}
else if (hours < 2) state[$1] = c2 "< 2 hours"
else if (hours < 5) state[$1] = c2 "< 5 hours"
else if (hours < 12) state[$1] = c2 "< 12 hours"
else state[$1] = c2 "< 1 day"
}
else if (days < 2) state[$1] = c3 "< 2 days"
else if (days < 3) state[$1] = c3 "< 3 days"
else if (days < 7) state[$1] = c3 "< 1 week"
else if (days < 14) state[$1] = c3 "< 2 weeks"
else if (days < 30) state[$1] = c3 "< 1 month"
else state[$1] = c4 "> 1 month"
state[$1] = state[$1] c0
}
ARGC = 1
}
/Address:/ {
ap = $5
last[ap] = now
if (state[ap] == "")
state[ap] = bold "###### NEW ######" c0
else
state[ap] = bold "*** Now ***" c0
seen[ap] = 1
scanned++
}
/Channel:/ {
gsub(":", " ")
channel[ap] = $2
}
/\(Channel / {
gsub(")", " ")
channel[ap] = $4
}
/Quality/ {
gsub("=", " ")
#if (qual[ap] == "" || qual[ap] < $2)
qual[ap] = $2
}
/ESSID:/ {
gsub("\"", " ")
if ($2 == "")
name[ap] = "[noname]"
else
name[ap] = $2
}
END {
PROCINFO["sorted_in"] = "@val_num_asc"
for(ap in channel) {
if (ARGV[1] == "now") {
if (seen[ap])
printf "%s %-25s %2d %2d\n", ap, name[ap], channel[ap], qual[ap]
} else
printf "%s %-25s %2d %2d %s %s\n", ap, name[ap], channel[ap], qual[ap], strftime("%d %a %b %Y %X", last[ap]), state[ap]
printf "%s %-25s %2d %2d %s\n", ap, name[ap], channel[ap], qual[ap], last[ap] > out
if (state[ap] ~ /NEW/)
new++
if (now - last[ap] < 24 * 3600) {
num[channel[ap]]++
qual_sum[channel[ap]] += qual[ap]
}
}
print "Total:", length(qual), " Scanned:", scanned, " New:", new
for(i = 1; i <= 13; i++)
printf "%2d %2d %3d\n", i, num[i], qual_sum[i] > stats
if (ARGV[1] == "plot") {
if (ARGV[2] == "sum")
cmd = "plot '" stats "' using 1:3 with boxes title 'Sum Quality'"
else if (ARGV[2] == "avg")
cmd = "plot '" stats "' using 1:($3/$2) with boxes title 'Avg Quality'"
else
cmd = "plot '" stats "' using 1:2 with boxes title '#APs'"
print cmd | "gnuplot -persist"
}
}