Skip to content

Commit d44ed08

Browse files
committed
Added tools_main.py
1 parent 0b85f5c commit d44ed08

1 file changed

Lines changed: 125 additions & 0 deletions

File tree

Networking-Tools/tools_main.py

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
# Import necessary modules
2+
import subprocess
3+
import tools
4+
5+
6+
# Function for displaying menu
7+
def Display_Menu():
8+
header = """
9+
___________________________
10+
| |
11+
| Basic Networking Tools |
12+
|_____________ __________|
13+
\ \
14+
^_ _^
15+
(o o)\_________
16+
(_ _)\ )/\/
17+
U ||----W||
18+
|| ||
19+
20+
### Available Tools:
21+
[1] Locate an IP address
22+
[2] Get the IP address of a domain
23+
[3] Ping a host or IP address
24+
[4] Port Scanner
25+
[5] Exit
26+
27+
* Type <clear> to clear previous commands
28+
* Type <q> or to abort operation of a tool
29+
30+
"""
31+
print(header)
32+
33+
34+
# Functionality of every option
35+
# Each option operates the tool related to the option number.
36+
def option_1():
37+
"""
38+
Option 1 --> IP Locater
39+
"""
40+
tools.locate_ip()
41+
Display_Menu()
42+
Home()
43+
44+
45+
def option_2():
46+
"""
47+
Option 2 --> IP Finder
48+
"""
49+
tools.get_ip()
50+
Display_Menu()
51+
Home()
52+
53+
54+
def option_3():
55+
"""
56+
Option 3 --> Pinging
57+
"""
58+
tools.ping()
59+
Display_Menu()
60+
Home()
61+
62+
63+
def option_4():
64+
"""
65+
Option 4 --> Port Scanner
66+
"""
67+
tools.port_scanner()
68+
Display_Menu()
69+
Home()
70+
71+
72+
def option_5():
73+
"""
74+
Option 5 --> Exit
75+
"""
76+
quit()
77+
78+
79+
# Function for selecting options
80+
def Home():
81+
"""
82+
Home of the program is selecting an option from available options.
83+
"""
84+
# Available options' numbers as shown in the menu
85+
available_options = (1, 2, 3, 4, 5)
86+
# Get the option's number.
87+
# If it is wrong, this while loop will run unless it gets
88+
# a proper number that is related with one of the available options.
89+
while True:
90+
try:
91+
selected_option = input("\nEnter your option\n>>> ")
92+
# In order to clear the mess created by the previous commands,
93+
# we define 'clear' command to clear up the screen from previous commands.
94+
if selected_option == 'clear':
95+
subprocess.call('cls', shell=True)
96+
Display_Menu()
97+
continue
98+
else:
99+
selected_option = int(selected_option)
100+
except ValueError:
101+
print("Please enter the number of the option")
102+
continue
103+
else:
104+
# If the given option number is not available, try to get an available option number.
105+
if selected_option not in available_options:
106+
print("The option is not available.\nTry another one.")
107+
continue
108+
else:
109+
break
110+
# Operate the option related to the given number
111+
if selected_option == 1:
112+
option_1()
113+
elif selected_option == 2:
114+
option_2()
115+
elif selected_option == 3:
116+
option_3()
117+
elif selected_option == 4:
118+
option_4()
119+
elif selected_option == 5:
120+
option_5()
121+
122+
123+
if __name__ == "__main__":
124+
Display_Menu()
125+
Home()

0 commit comments

Comments
 (0)