HokieGeek / dotfiles

My linux config files
0 stars 0 forks source link

Create wifi connection script #51

Closed HokieGeek closed 10 years ago

HokieGeek commented 10 years ago

Step The First: Write code that just reads this file and performs a connection Step The Second: Write code that can update the file

HokieGeek commented 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

HokieGeek commented 10 years ago

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()
HokieGeek commented 10 years ago

Halting work on this as I think I am overthinking it. See referenced issue

HokieGeek commented 10 years ago

I'm an idiot