Advertisement
Guest User

Untitled

a guest
Apr 26th, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. ////network_info.py
  2.  
  3. import subprocess
  4. import json
  5. import re
  6.  
  7.  
  8.  
  9. iwconfig = subprocess.Popen(('iwconfig'), stdout=subprocess.PIPE)
  10. ssid = subprocess.check_output(('grep', 'wlan0'), stdin=iwconfig.stdout)
  11. ssid = ssid.decode("utf8")
  12. ssid = ssid.split(":")[1]
  13. ssid = re.sub('\s+','',ssid)
  14.  
  15. if '"' in ssid:
  16. ssid = ssid.replace('"', '')
  17. else:
  18. ssid = None
  19.  
  20.  
  21. with open('/sys/class/net/eth0/carrier', 'r') as myfile:
  22. ethernet=myfile.read().replace('\n', '')
  23.  
  24. if (ethernet == "1"):
  25. ethernet = "Tilkoblet"
  26. else:
  27. ethernet = "Frakoblet"
  28.  
  29.  
  30. data = {}
  31. data['ssid'] = ssid
  32. data['ethernet'] = ethernet
  33.  
  34. json_data = json.dumps(data)
  35. print (json_data)
  36.  
  37.  
  38.  
  39. ////reboot.py
  40. import os
  41.  
  42. print ("Rebooting")
  43. os.system('sudo shutdown -r now')
  44.  
  45.  
  46.  
  47. /////test.py
  48. import sys
  49. import fileinput
  50.  
  51. filename = "/etc/wpa_supplicant/wpa_supplicant.conf"
  52.  
  53. info = sys.argv[1]
  54. info = info.split(";")
  55.  
  56. raw = open(filename, "r+")
  57. contents = raw.read().split("\n")
  58. raw.seek(0)
  59. raw.truncate()
  60. raw.write('ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev\n'
  61. 'ap_scan=1\n'
  62. 'update_config=1\n'
  63. '\n'
  64. 'network={\n'
  65. '\tssid="' + info[0] + '"\n'
  66. '\tpsk="' + info[1] + '"\n'
  67. '\tkey_mgmt=' + info[2] + '\n'
  68. '}\n')
  69.  
  70.  
  71. print "Got arguments: ", info[1]
  72.  
  73.  
  74.  
  75.  
  76. ///////////edit_file.py
  77. import sys
  78. import fileinput
  79.  
  80. info = sys.argv[1]
  81. info = info.split(";")
  82.  
  83. ##fil = info[0]
  84. ##finnlinje = info[1]
  85. ##nylinje = info[2]
  86.  
  87.  
  88. def editFile(fil, finnlinje, nylinje):
  89. text = finnlinje
  90. new_text = nylinje
  91. x = fileinput.input(files=fil, inplace=1)
  92. for line in x:
  93. if text in line:
  94. line = new_text
  95. sys.stdout.write(line),
  96. x.close()
  97.  
  98. editFile(fil, finnlinje, nylinje)
  99.  
  100. print(info)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement