Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ////network_info.py
- import subprocess
- import json
- import re
- iwconfig = subprocess.Popen(('iwconfig'), stdout=subprocess.PIPE)
- ssid = subprocess.check_output(('grep', 'wlan0'), stdin=iwconfig.stdout)
- ssid = ssid.decode("utf8")
- ssid = ssid.split(":")[1]
- ssid = re.sub('\s+','',ssid)
- if '"' in ssid:
- ssid = ssid.replace('"', '')
- else:
- ssid = None
- with open('/sys/class/net/eth0/carrier', 'r') as myfile:
- ethernet=myfile.read().replace('\n', '')
- if (ethernet == "1"):
- ethernet = "Tilkoblet"
- else:
- ethernet = "Frakoblet"
- data = {}
- data['ssid'] = ssid
- data['ethernet'] = ethernet
- json_data = json.dumps(data)
- print (json_data)
- ////reboot.py
- import os
- print ("Rebooting")
- os.system('sudo shutdown -r now')
- /////test.py
- import sys
- import fileinput
- filename = "/etc/wpa_supplicant/wpa_supplicant.conf"
- info = sys.argv[1]
- info = info.split(";")
- raw = open(filename, "r+")
- contents = raw.read().split("\n")
- raw.seek(0)
- raw.truncate()
- raw.write('ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev\n'
- 'ap_scan=1\n'
- 'update_config=1\n'
- '\n'
- 'network={\n'
- '\tssid="' + info[0] + '"\n'
- '\tpsk="' + info[1] + '"\n'
- '\tkey_mgmt=' + info[2] + '\n'
- '}\n')
- print "Got arguments: ", info[1]
- ///////////edit_file.py
- import sys
- import fileinput
- info = sys.argv[1]
- info = info.split(";")
- ##fil = info[0]
- ##finnlinje = info[1]
- ##nylinje = info[2]
- def editFile(fil, finnlinje, nylinje):
- text = finnlinje
- new_text = nylinje
- x = fileinput.input(files=fil, inplace=1)
- for line in x:
- if text in line:
- line = new_text
- sys.stdout.write(line),
- x.close()
- editFile(fil, finnlinje, nylinje)
- print(info)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement