Closed HokieGeek closed 10 years ago
import subprocess
# Retrieve current wifi hotspots
output = subprocess.check_output("iw dev ??? scan...", shell=True)
foundDevices = dict([line.strip().split(' ') for line in output])
# Retrieve known wifi hotspots
knownDevices = dict([line.strip().split(',') for line in open('/??/../??/known_devices')])
hits = set(knownDevices.keys()) & set(foundDevices.keys())
top = hits.pop()
security = foundDevices[top]
key = knownDevices[top]
print "found: ", foundDevices
print "known: ", knownDevices
print "hits:", hits
print "Security:", security
print "Key:", key
Currently known issue: Have been unable to maintain sort order of known devices
If check output doesn't work, try this:
import os
import tempfile
tempFile = tempfile.NamedTemporaryFile()
os.system('iw dev ?? scan | grep SSID > %s' % tempFile.name)
output = [line.strip() for line in tempFile]
tempFile.close()
Halting work on this as I think I am overthinking it. See referenced issue
I'm an idiot
priority,ssid,security,key
orssid,key
. I'm liking the latter moreStep The First: Write code that just reads this file and performs a connection Step The Second: Write code that can update the file