-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoggle-network
More file actions
executable file
·41 lines (33 loc) · 1.04 KB
/
toggle-network
File metadata and controls
executable file
·41 lines (33 loc) · 1.04 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
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# Copyright (c) 2018 Jared Daniel Carbonell Recomendable.
import sys
import subprocess
com_get_status = 'nmcli n connectivity check'
com_activate = 'nmcli n on'
com_deactivate = 'nmcli n off'
cannot_get_status = '\nUnable to get active status of network.\nExiting...\n'
def check_network():
"""Carry out the process of checking whether the network is active."""
status = subprocess.check_output(com_get_status, shell=True).decode()
if 'full' in status:
return True
return False
def run():
"""Carry out the process of toggling whether the network is active."""
status = check_network()
if status:
to_run = com_deactivate
else:
to_run = com_activate
subprocess.run(['bash', '-c', to_run])
def show_help():
"""Show the help documentation for the program."""
help_doc = '''Usage: toggle-network
Simply toggles the network on or off.'''
print(help_doc)
if __name__ == '__main__':
if len(sys.argv) == 1:
run()
else:
show_help()