-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSwitchWifi.py
84 lines (76 loc) · 2.8 KB
/
SwitchWifi.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
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
# 4 bouttons pour couper/allumer le wifi 2.4 et 5 ghz
import wiringpi2 as wiringpi
import paramiko
import sys
import select
from time import sleep # allows us a time delay
wiringpi.wiringPiSetupGpio()
wiringpi.pinMode(27, 0) # sets GPIO 27 to input
cmd1 = "wl radio off"
cmd2 = "wl radio on"
cmd3 = "wl -i eth2 radio off"
cmd4 = "wl -i eth2 radio on"
host = '192.168.1.1'
portR = 69
utilisateur = 'root'
mdp = "coucou"
timer = 0
try:
while True:
if wiringpi.digitalRead(27): # If button on GPIO27 pressed
print "Boutton B"
print "Connection ssh en cours"
ssh = paramiko.SSHClient() #loading SSH client
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(host, port=portR, username=utilisateur, password=mdp, look_for_keys=True) #connection to tomatousb router
sleep(2)
print "Connected"
ssh_stdin, ssh_stdout, ssh_stderr = ssh.exec_command(cmd1)
print "Wifi 2.4 Ghz desactivated"
sleep(1)
ssh.close()
print "Connection closed"
elif wiringpi.digitalRead(2): # If button on GPIO02 pressed
print "Boutton C"
print "Connection ssh en cours"
ssh = paramiko.SSHClient() #loading SSH client
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(host, port=portR, username=utilisateur, password=mdp, look_for_keys=True) #connection to tomatousb router
sleep(2)
print "Connected"
ssh_stdin, ssh_stdout, ssh_stderr = ssh.exec_command(cmd4)
print "Wifi 5 Ghz activated"
sleep(1)
ssh.close()
print "Connection closed"
elif wiringpi.digitalRead(17): # If button on GPIO17 pressed
print "Boutton D"
print "Connection ssh en cours"
ssh = paramiko.SSHClient() #loading SSH client
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(host, port=portR, username=utilisateur, password=mdp, look_for_keys=True) #connection to tomatousb router
sleep(2)
print "Connected"
ssh_stdin, ssh_stdout, ssh_stderr = ssh.exec_command(cmd3)
print "Wifi 5 Ghz desactivated"
sleep(1)
ssh.close()
print "Connection closed"
elif wiringpi.digitalRead(22): # If button on GPIO22 pressed
print "Boutton A"
print "Connection ssh en cours"
ssh = paramiko.SSHClient() #loading SSH client
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(host, port=portR, username=utilisateur, password=mdp, look_for_keys=True) #connection to tomatousb router
sleep(2)
print "Connected"
ssh_stdin, ssh_stdout, ssh_stderr = ssh.exec_command(cmd2)
print "Wifi 2.4 Ghz activated"
sleep(1)
ssh.close()
print "Connection closed"
else:
print "Waiting something happens...." # waiting button pressed
sleep(0.4) # delay
finally:
print "bye"