-
Notifications
You must be signed in to change notification settings - Fork 0
/
wlan_config.py
42 lines (33 loc) · 1.01 KB
/
wlan_config.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
import argparse
import telnetlib
parser = argparse.ArgumentParser(
usage="%(prog)s <host> <user> <passwd> <on | off>")
parser.add_argument("host", help="HOST (IP) for connection")
parser.add_argument("user", help="USER for connection")
parser.add_argument("password", help="PASSWORD for connection")
parser.add_argument("action", choices=["on", "off"],
help="[on | off] Enable or disable Wiffi")
parser.add_argument("-p", "--port", default=23,
help="PORT for connection (default 23)")
args = parser.parse_args()
#vars
HOST = args.host
USER = args.user
PASSWORD = args.password
PORT = args.port
ACTION = args.action
# connection
telnet = telnetlib.Telnet(HOST, PORT)
# credentials
telnet.read_until("Login: ")
telnet.write(USER + "\n")
telnet.read_until("Password: ")
telnet.write(PASSWORD + "\n")
# enabling - disabling WLAN
telnet.read_until(" > ")
telnet.write("wlctl radio " + ACTION + "\n")
telnet.write("quit \n")
output = telnet.read_all()
# uncoment for debuggin
#print output
print "WLAN is %s" % ACTION