-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
54 lines (40 loc) · 1.32 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
username = "user"
password = "password"
server = "server_address"
share = "sharename"
mount_point = "~/mnt"
ssid = ""
sleep_time = 20
import os
import time
import subprocess
def ssid_connected():
wifi_info = subprocess.check_output(['/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport','-I']).decode("UTF-8")
if ssid in wifi_info:
print("On correct wifi network")
return True
print("Not on required wifi network")
return
def sort_mount_point():
if not os.path.exists(mount_point):
print("mount point doesn't exist, creating...")
os.makedirs(mount_point)
time.sleep(0.2)
def is_mounted():
mnts = subprocess.check_output(["mount"]).decode("UTF-8")
if mount_point in mnts:
return True
return
def connect():
os.system("mount_smbfs //{}:{}@{}/{} {}".format(username, password, server, share, mount_point))
def run():
while True:
if ssid_connected() and not is_mounted():
sort_mount_point()
time.sleep(0.2)
connect()
# if connected to ssid then mount server else sleep
time.sleep(sleep_time)
if __name__ == "__main__":
run()
# /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I | grep -w SSID | awk '{print $2}'