summaryrefslogtreecommitdiff
path: root/boot/wifi.py
diff options
context:
space:
mode:
authorschneefux <schneefux+commit@schneefux.xyz>2014-03-30 16:03:44 -0400
committerschneefux <schneefux+commit@schneefux.xyz>2014-03-30 16:03:44 -0400
commitd31fabf8cff5dae02e3fc759a4203bd374dddc99 (patch)
tree888ec4e6d98154f862a3b9cd17a3394b657bc02e /boot/wifi.py
parent4182b5e096e081158dddd4ad5d031af94fcc63de (diff)
downloadjasper-client-d31fabf8cff5dae02e3fc759a4203bd374dddc99.tar.gz
jasper-client-d31fabf8cff5dae02e3fc759a4203bd374dddc99.zip
Initial commit
Diffstat (limited to 'boot/wifi.py')
-rwxr-xr-xboot/wifi.py60
1 files changed, 60 insertions, 0 deletions
diff --git a/boot/wifi.py b/boot/wifi.py
new file mode 100755
index 0000000..7e2fa43
--- /dev/null
+++ b/boot/wifi.py
@@ -0,0 +1,60 @@
+import yaml
+import os, subprocess
+
+class Wifi:
+
+ access_points = []
+
+ def __init__(self):
+
+ subprocess.call("iwlist wlan0 scan > temp.txt", shell = True)
+ output = open("temp.txt")
+ lines = output.readlines()
+
+ for index, line in enumerate(lines):
+
+ if "Address" in line:
+
+ address = line[29:-1]
+ name = lines[index + 1].split("\"")[1]
+ self.access_points.append(name)
+
+ self.access_points = list(set(self.access_points))
+
+ os.system("rm temp.txt")
+
+ def add_wifi(self, SSID, KEY=""):
+ networks = yaml.safe_load(open("networks.yml", "r"))
+
+ # add new network to front of list
+ network = {"SSID": SSID, "KEY": KEY}
+ networks.insert(0, network)
+
+ with open('networks.yml', 'w') as outputFile:
+ output = yaml.dump(networks)
+ outputFile.write(output)
+
+ def set_default_wifi(self, SSID, KEY=""):
+
+ text = open("connect.txt", "r").read()
+ text = text.replace("{{ SSID }}", SSID)
+ text = text.replace("{{ KEY }}", KEY)
+
+ outputFile = open("/etc/network/interfaces", "w")
+ outputFile.write(text)
+ outputFile.flush()
+ outputFile.close()
+
+ subprocess.call(["sudo", "/etc/init.d/networking", "restart"])
+
+ def setup_adhoc(self):
+
+ text = open("broadcast.txt", "r").read()
+ outputFile = open("/etc/network/interfaces","w")
+ outputFile.write(text)
+ outputFile.flush()
+ outputFile.close()
+
+ subprocess.call(["sudo", "/etc/init.d/networking", "restart"])
+ subprocess.call(['sudo', '/usr/sbin/dhcpd', '-q', '-cf', '/etc/dhcp/dhcpd.conf', '-pf', '/var/run/dhcpd.pid'])
+ subprocess.call(["sudo", "/etc/init.d/networking", "restart"]) \ No newline at end of file