-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexercise4.py
59 lines (49 loc) · 1.37 KB
/
exercise4.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
def openPorts():
import subprocess
subprocess.call(["netstat", "-l"])
def diskUsage():
import subprocess
subprocess.call(["df", "-h"])
def nics():
import subprocess
subprocess.call(["ifconfig", "-a"])
def showRouteT():
import subprocess
subprocess.call(["netstat", "-rn"])
def tmpUsage():
import subprocess
subprocess.call(["du","-h", "/tmp"])
def tmpEmptyFiles():
import subprocess
subprocess.call(["find", "/tmp", "-type", "f", "-empty"])
def processRoot():
import subprocess
subprocess.call(["ps", "-u", "root"])
def menu():
print("Please select one of the following options: " )
print("1. show ports that are listening")
print("2. show disk usage on your system")
print("3. show network interfaces")
print("4. show routing table")
print("5. show usageof /tmp directory")
print("6. show empty files in /tmp directory")
print("7. show all processes of the user root")
choice = int(input("Please select one of the above options: "))
if choice == 1:
openPorts()
elif choice == 2:
diskUsage()
elif choice == 3:
nics()
elif choice == 4:
showRouteT()
elif choice == 5:
tmpUsage()
elif choice == 6:
tmpEmptyFiles()
elif choice == 7:
processRoot()
else:
print("wrong option")
if __name__=="__main__":
menu()