forked from Nikhilesh-M/openwrt-presence
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwrtwifistareport.sh
67 lines (67 loc) · 2.27 KB
/
wrtwifistareport.sh
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
#/bin/sh
#
# Info: OpenWRT Wifi STA Syslog Reporter
# Filename: wrtwifistareport.sh
# Usage: This script gets called by cron every X minutes.
# #
# # Force an immediate report via syslog to the collector server.
# sh "/root/wrtwifistareport.sh"
#
# Installation:
#
# chmod +x "/root/wrtwifistareport.sh"
# LUCI: System / Scheduled Tasks / Add new row
# */5 * * * * /bin/sh "/root/wrtwifistareport.sh" >/dev/null 2>&1
# Restart Cron:
# /etc/init.d/cron restart
#
# -----------------------------------------------------
# -------------- START OF FUNCTION BLOCK --------------
# -----------------------------------------------------
dumpLocalAssociatedStations ()
{
#
# Usage: dumpLocalAssociatedStations
# Returns: iw dev <all wlan devices> station dump
# cumulated result.
# Example Result: "aa:bb:cc:dd:ee:ff|" (without newline at the end)
#
# Called By: MAIN
#
#
# Get all wlan interfaces with sub-SSIDs:
# e.g. wlan0, wlan0-1, wlan0-2, wlan1, wlan1-1, wlan1-2, ...
iw dev | grep -F "wlan" | cut -d " " -f 2 | while read file;
do
#
# "file" contains one SSID Wifi Interface, e.g. "wlan0-1"
#
# Get associated stations of current wlanX interface.
# echo -n "$(iw dev "${file}" station dump 2> /dev/null | grep -Fi "on wlan" | cut -d " " -f 2 | sed "s/^/${file},/" | tr '\n' '|')"
#
# Get authorized stations of current wlanX interface.
echo -n "$(iw dev "${file}" station dump 2> /dev/null | grep "\(on wlan\|authorized:*.\)" | grep -B 1 "^.*authorized:.*yes$" | grep -v "^.*authorized:.*$" | cut -d " " -f 2 | sed "s/^/${file},/" | tr '\n' '|')"
#
done
#
# Content already returned because iw dev was called loudly.
return
}
# ---------------------------------------------------
# -------------- END OF FUNCTION BLOCK --------------
# ---------------------------------------------------
#
#
#
# ---------------------------------------------------
# ----------------- SCRIPT MAIN ---------------------
# ---------------------------------------------------
#
# Write associated STA client MAC addresses to local syslog.
# If a syslog-ng server is configured in LUCI, the log will be forwarded to it.
logger -t "wrtwifistareport" "$(echo ";$(dumpLocalAssociatedStations)")"
#
# For testing purposes only.
# echo ";$(dumpLocalAssociatedStations)"
#
exit 0