Skip to content

Instantly share code, notes, and snippets.

@sneha-belkhale
Last active March 26, 2021 18:20
  • Star 7 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save sneha-belkhale/dffa4c8dc2aed8dcce79850af2071e08 to your computer and use it in GitHub Desktop.
# Run this script in Atom with the FoxDot Extension.
# Make sure "filepath" points to your TCPDump data.
# Set resample to True if you want to continuously resample the wifi packet data,
# if so, you will need to continuously run the TCPDump script which contains the following line:
# sudo tcpdump -y 'IEEE802_11_RADIO' -i en0 -c 3000 -I -ttttt > "filepath"
# set up this script to be run without sudo using visudo.
# at the end of this file, you will have all signals stored in the dictionary signalDictAligned,
# pipe these arrays into foxdot players and jam!
import os
import re
import time as timeLib
filepath = '/Users/xxx/packetDump.txt'
tcpDumpCommand = "sudo /Users/xxx/tcpDump.sh"
resample = False
# -----------------------------------
looping = True
while looping:
signalDict = {}
if resample:
p = os.system(tcpDumpCommand)
with open(filepath) as fp:
line = fp.readline()
cnt = 1
while line:
line = fp.readline()
os.write(2, str.encode(line))
signal = re.search('(\S*)dBm signal', line)
time = re.search('00:00:(\S*)', line)
if signal == None or time == None:
continue
lastTime = float(time.group(1))
key = re.search('Beacon (\S*)', line)
if key == None:
key = re.search('(\S*) \(oui Unknown', line)
if key == None:
continue
address = key.group(1)
if address in signalDict:
signalDict[address].append((signal.group(1), lastTime))
else:
signalDict[address] = [(signal.group(1), lastTime)]
cnt += 1
fp.close()
maxLength = 80
signalDictSorted = []
for address in signalDict:
signalDictSorted.append(signalDict[address])
signalDictSorted.sort(key=len, reverse=True)
signalDictAligned = []
for i, signalList in enumerate(signalDictSorted):
if i > 9:
continue
signalAligned = [None] * (maxLength+1)
for signal in signalList:
time = signal[1]
idx = int(maxLength * (time/lastTime))
if idx > maxLength:
continue
signalAligned[idx] = int(0.4*pow(float(signal[0]),2)/100 + 20)
signalDictAligned.append(signalAligned)
count = 0
execute("Clock.clear()")
count = 0
looping = resample
# --------------------------------------
count = 0
for signals in signalDictAligned:
playerval = "d" + str(count)
count = count + 1
execute(playerval + ">> pads(signals, dur=0.25)")
sudo tcpdump -y 'IEEE802_11_RADIO' -i en0 -c 3000 -I -ttttt > /Users/xxx/packetDump.txt
@sneha-belkhale
Copy link
Author

FoxDot Wifi Soundscapes

Reveal the intangible dimension of wifi by using TCPDump to capture packets in monitor mode and sonifying their signal strengths with python / FoxDot

Script Tips

[+] Run this script in Atom with the FoxDot Extension.

[+] Make sure filepath points to your TCPDump data.

[+] Set resample to True if you want to continuously resample the wifi packet data,
if so, you will need a bash script which contains the following line:
sudo tcpdump -y 'IEEE802_11_RADIO' -i en0 -c 3000 -I -ttttt > filepath

set up this script to be run without sudo using visudo.

[+] at the end of this file, you will have all signals stored in the dictionary signalDictAligned,
pipe these arrays into foxdot players and jam!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment