Advertisement
Guest User

Untitled

a guest
Apr 26th, 2018
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 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.  
  48.  
  49.  
  50.  
  51. ///////////edit_file.py
  52. import sys
  53. import fileinput
  54.  
  55. info = sys.argv[1]
  56. info = info.split(";")
  57.  
  58. ##fil = info[0]
  59. ##finnlinje = info[1]
  60. ##nylinje = info[2]
  61.  
  62.  
  63. def editFile(fil, finnlinje, nylinje):
  64. text = finnlinje
  65. new_text = nylinje
  66. x = fileinput.input(files=fil, inplace=1)
  67. for line in x:
  68. if text in line:
  69. line = new_text
  70. sys.stdout.write(line),
  71. x.close()
  72.  
  73. editFile(fil, finnlinje, nylinje)
  74.  
  75. print(info)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement