-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathwifisentinel.py
38 lines (34 loc) · 966 Bytes
/
wifisentinel.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
#!/usr/bin/python
"""
WIFI network protector during flight
usage:
./protector.py <internal program with args>
"""
import subprocess
import time
import sys
DRONE_IP_LIST = ['192.168.1.2', '192.168.1.3', '192.168.1.4']
def myWiFiIP():
ret = None
if sys.platform == 'linux2':
p = subprocess.Popen( ["/sbin/ifconfig", "wlan0"], stdout=subprocess.PIPE )
for line in p.stdout.readlines():
if "inet adr:" in line: # Czech linux (!)
ret = line.strip().split()[1][4:] # cut "adr:"
else:
p = subprocess.Popen( "ipconfig", stdout=subprocess.PIPE )
for line in p.stdout.readlines():
if "IPv4 Address" in line and "192.168.56.1" not in line:
ret = line.strip().split()[-1]
return ret
print sys.argv
while True:
ip = myWiFiIP()
while ip not in DRONE_IP_LIST:
print ip
time.sleep(3)
ip = myWiFiIP()
print "CONNECTED TO", ip
if subprocess.call( sys.argv[1:] ) == 0:
break
print "RECOVERY"