Created
June 22, 2017 10:12
-
-
Save magicleon94/d2ae99b3f41e3aaabaeb998bae47a6a1 to your computer and use it in GitHub Desktop.
Count surrounding devices based on captured probe requests on Linux
This file contains hidden or 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
#!/bin/bash | |
Red='\e[0;31m' | |
allowAbort=true; | |
exitHandler(){ | |
if $allowAbort; then | |
echo "LULLOOOOOOOOOOOOOOOOOOOOOOOOO" | |
rm tmp count; | |
exit 1; | |
fi | |
} | |
ifconfig wlan0 down; | |
sleep 1; | |
iwconfig wlan0 mode monitor; | |
sleep 1; | |
ifconfig wlan0 up; | |
allowAbort=false; | |
echo " $RED Listening for probe requests, hit CTRL+C to terminate listening and count devices"; | |
#tcpdump -i wlan0 -e -s 256 subtype probe-req > tmp; | |
#tcpdump -i wlan0 type mgt subtype probe-req or arp -e -v | |
tcpdump -i wlan0 type mgt subtype probe-req or arp -e -v > tmp | |
ifconfig wlan0 down; | |
sleep 1; | |
iwconfig wlan0 mode managed; | |
sleep 1; | |
ifconfig wlan0 up; | |
allowAbort=true; | |
cat tmp | awk -F "SA" '{ print $2 }' | awk '{ print $1 }' > count | |
python macCounter.py |
This file contains hidden or 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
src = open('count','r') | |
strings = src.read() | |
macs = strings.split('\n'); | |
nodup = [] | |
count = 0; | |
for mac in macs: | |
if not ( mac in nodup ): | |
if len(mac)>0: | |
nodup.append(mac) | |
count += 1 | |
device = 'devices' | |
if count==1: | |
device='device' | |
print str(count) + " nearby " + device + " discovered." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment