-
Notifications
You must be signed in to change notification settings - Fork 228
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #473 from nodogsplash/4.3.4beta
fas: get-client-interface
- Loading branch information
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
forward_authentication_service/libs/get_client_interface.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/bin/sh | ||
#Copyright (C) Blue Wave Projects and Services 2015-2019 | ||
#This software is released under the GNU GPL license. | ||
|
||
# This script requires the iw package (usually available by default) | ||
|
||
# mac address of client is passed as a command line argument | ||
mac=$1 | ||
|
||
# exit if mac not passed | ||
if [ -z $mac ]; then | ||
exit 1 | ||
fi | ||
|
||
# Get default interface | ||
# This will be the interface NDS is bound to eg. br-lan | ||
clientif=$(ip -4 neigh | awk -F ' ' 'match($s,"'"$mac"' REACHABLE")>0 {printf $3" "}') | ||
|
||
if [ -z $clientif ]; then | ||
# The client has gone offline eg battery saving or switched to another ssid | ||
exit 1 | ||
fi | ||
|
||
# Get list of wireless interfaces on this device | ||
# This list will contain all the wireless interfaces configured on the device | ||
# eg wlan0, wlan0-1, wlan1, wlan1-1 etc | ||
interface_list=$(iw dev | awk -F 'Interface ' 'NF>1{printf $2" "}') | ||
|
||
# Scan the wireless interfaces on this device for the client mac | ||
for interface in $interface_list; do | ||
macscan=$(iw dev $interface station dump | awk -F " " 'match($s, "'"$mac"'")>0{print $2}') | ||
if [ ! -z $macscan ]; then | ||
clientif=$interface | ||
break | ||
fi | ||
done | ||
|
||
# Return the local interface the client is using | ||
echo $clientif | ||
|
||
exit 0 | ||
|