Repository navigation
Expand file tree
/
Copy pathcontroladora_com_of.py
More file actions
86 lines (69 loc) · 4.53 KB
/
Copy pathcontroladora_com_of.py
File metadata and controls
86 lines (69 loc) · 4.53 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import subprocess
import time
def print_debug(staA, staAt, staB, staBt):
print "staA %d %s" % (staAt, staA)
print "staB %d %s" % (staBt, staB)
while True:
stasAP1 = int(subprocess.check_output("sudo hostapd_cli -i ap1-wlan1 all_sta | grep aid | wc -l", shell=True).splitlines()[0])
print stasAP1
stasAP2 = int(subprocess.check_output("sudo hostapd_cli -i ap2-wlan1 all_sta | grep aid | wc -l", shell=True).splitlines()[0])
print stasAP2
stasAP3 = int(subprocess.check_output("sudo hostapd_cli -i ap3-wlan1 all_sta | grep aid | wc -l", shell=True).splitlines()[0])
print stasAP3
if stasAP1 == 2:
print "\n\n\n===========AP 1 desbalanceado============\n"
staA = subprocess.check_output("sudo hostapd_cli -i ap1-wlan1 all_sta | grep : | head -1", shell=True).splitlines()[0]
staB = subprocess.check_output("sudo hostapd_cli -i ap1-wlan1 all_sta | grep : | tail -1", shell=True).splitlines()[0]
staAt = int(subprocess.check_output("sudo hostapd_cli -i ap1-wlan1 sta "+ staA + "| grep conn | cut -d= -f2", shell=True).splitlines()[0])
staBt = int(subprocess.check_output("sudo hostapd_cli -i ap1-wlan1 sta "+ staB + "| grep conn | cut -d= -f2", shell=True).splitlines()[0])
print_debug(staA,staAt, staB, staBt)
if staAt >= staBt:
print "\nDisassociando %s" %staB
print "\nTempo de Associacao %d\n" %staBt
subprocess.call("sudo hostapd_cli -i ap1-wlan1 disassociate "+ staB, shell=True)
else:
print "\nDisassociando %s" %staA
print "\nTempo de Associacao %d\n" %staAt
subprocess.call("sudo hostapd_cli -i ap1-wlan1 disassociate "+ staA, shell=True)
print "\n========Aguardando confirmar desassociacao...========\n"
subprocess.call(" sudo ovs-ofctl del-flows s1", shell=True)
while stasAP1 == 2:
stasAP1 = int(subprocess.check_output("sudo hostapd_cli -i ap1-wlan1 all_sta | grep aid | wc -l", shell=True).splitlines()[0])
time.sleep(1)
if stasAP2 == 2:
print "\n\n\n===========AP 2 desbalanceado============\n"
staA = subprocess.check_output("sudo hostapd_cli -i ap2-wlan1 all_sta | grep : | head -1", shell=True).splitlines()[0]
staB = subprocess.check_output("sudo hostapd_cli -i ap2-wlan1 all_sta | grep : | tail -1", shell=True).splitlines()[0]
staAt = int(subprocess.check_output("sudo hostapd_cli -i ap2-wlan1 sta "+ staA + "| grep conn | cut -d= -f2", shell=True).splitlines()[0])
staBt = int(subprocess.check_output("sudo hostapd_cli -i ap2-wlan1 sta "+ staB + "| grep conn | cut -d= -f2", shell=True).splitlines()[0])
if staAt >= staBt:
print "\nDisassociando %s" %staB
print "\nTempo de Associacao %d\n" %staBt
subprocess.call("sudo hostapd_cli -i ap2-wlan1 disassociate "+ staB, shell=True)
else:
print "\nDisassociando %s" %staA
print "\nTempo de Associacao %d\n" %staAt
subprocess.call("sudo hostapd_cli -i ap2-wlan1 disassociate "+ staA, shell=True)
print "\n========Aguardando confirmar desassociacao...========\n"
subprocess.call(" sudo ovs-ofctl del-flows s1", shell=True)
while stasAP2 == 2:
stasAP2 = int(subprocess.check_output("sudo hostapd_cli -i ap2-wlan1 all_sta | grep aid | wc -l", shell=True).splitlines()[0])
if stasAP3 == 2:
print "\n\n\n===========AP 3 desbalanceado============\n"
staA = subprocess.check_output("sudo hostapd_cli -i ap3-wlan1 all_sta | grep : | head -1", shell=True).splitlines()[0]
staB = subprocess.check_output("sudo hostapd_cli -i ap3-wlan1 all_sta | grep : | tail -1", shell=True).splitlines()[0]
staAt = int(subprocess.check_output("sudo hostapd_cli -i ap3-wlan1 sta "+ staA + "| grep conn | cut -d= -f2", shell=True).splitlines()[0])
staBt = int(subprocess.check_output("sudo hostapd_cli -i ap3-wlan1 sta "+ staB + "| grep conn | cut -d= -f2", shell=True).splitlines()[0])
if staAt >= staBt:
print "\nDisassociando %s" %staB
print "\nTempo de Associacao %d\n" %staBt
subprocess.call("sudo hostapd_cli -i ap3-wlan1 disassociate "+ staB, shell=True)
else:
print "\nDisassociando %s" %staA
print "\nTempo de Associacao %d\n" %staAt
subprocess.call("sudo hostapd_cli -i ap3-wlan1 disassociate "+ staA, shell=True)
print "\n========Aguardando confirmar desassociacao...========\n"
subprocess.call(" sudo ovs-ofctl del-flows s1", shell=True)
while stasAP3 == 2:
stasAP3 = int(subprocess.check_output("sudo hostapd_cli -i ap3-wlan1 all_sta | grep aid | wc -l", shell=True).splitlines()[0])
time.sleep(2)