-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnetportcontrol.sh
251 lines (245 loc) · 8.58 KB
/
netportcontrol.sh
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
#!/bin/bash
# Network Port Controller v1.1
# GitHub: https://github.com/leonardob0rges
printf "\e[1;36m _ _ _ ____ _ ____ _ _ \e[0m\n"
printf "\e[1;36m| \ | | ___| |_| _ \ ___ _ __| |_ / ___|___ _ __ | |_ _ __ ___ | | \e[0m\n"
printf "\e[1;36m| \| |/ _ \ __| |_) / _ \| '__| __| | | / _ \| '_ \| __| '__/ _ \| | \e[0m\n"
printf "\e[1;36m| |\ | __/ |_| __/ (_) | | | |_ | |__| (_) | | | | |_| | | (_) | | \e[0m\n"
printf "\e[1;36m|_| \_|\___|\__|_| \___/|_| \__| \____\___/|_| |_|\__|_| \___/|_| v1.1\e[0m\n"
echo ""
printf " \e[1m\e[4;36mNetwork Port Controller coded by: @leonardob0rges (GitHub)\e[0m\n"
echo ""
printf " \e[1;37m The Network Port Controller is a simple shellscript\e[0m\n"
printf " \e[1;37m that uses Linux Firewall UFW to defines rules as \e[0m\n"
printf " \e[1;37m allow or deny determined ports \e[0m\n"
echo ""
# USER'S CHOiCES
sleep 0.2
printf "\e[0m\e[1;36m[\e[1;37m01\e[0m\e[0m\e[1;36m]\e[0m \e[0m\e[1;33mallow PORT\e[0m \e[0m\e[1;36m[\e[1;37m04\e[0m\e[0m\e[1;36m]\e[0m \e[0m\e[1;33menable UFW\e[0m \e[0m\e[1;36m[\e[1;37m07\e[0m\e[0m\e[1;36m]\e[0m \e[0m\e[1;33mreset UFW\e[0m"
echo ""
printf "\e[0m\e[1;36m[\e[1;37m02\e[0m\e[0m\e[1;36m]\e[0m \e[0m\e[1;33mdeny PORT\e[0m \e[0m\e[1;36m[\e[1;37m05\e[0m\e[0m\e[1;36m]\e[0m \e[0m\e[1;33mdisable UFW\e[0m \e[0m\e[1;36m[\e[1;37m08\e[0m\e[0m\e[1;36m]\e[0m \e[0m\e[1;33m...\e[0m"
echo ""
printf "\e[0m\e[1;36m[\e[1;37m03\e[0m\e[0m\e[1;36m]\e[0m \e[0m\e[1;33mstatus UFW\e[0m \e[0m\e[1;36m[\e[1;37m06\e[0m\e[0m\e[1;36m]\e[0m \e[0m\e[1;33mreload UFW\e[0m \e[0m\e[1;36m[\e[1;37m09\e[0m\e[0m\e[1;36m]\e[0m \e[0m\e[1;33mExit\e[0m"
echo ""
echo ""
read -p $'\e[1;36m[*]\e[1m \e[1;37mChoose an option:\e[1m ' option
if [[ $option == 1 || $option == 01 ]];
then
echo ""
read -p $'\e[1;36mPORT:\e[1m ' port
read -p $'\e[1;36mPROTOCOL:\e[1m ' protocol
sudo ufw allow $port/$protocol
sleep 2.15
clear && ./netportcontrol.sh
elif [[ $option == 2 || $option == 02 ]];
then
echo ""
read -p $'\e[1;36mPORT:\e[1m ' port
read -p $'\e[1;36mPROTOCOL:\e[1m ' protocol
sudo ufw deny $port/$protocol
sleep 2.15
clear && ./netportcontrol.sh
elif [[ $option == 3 || $option == 03 ]];
then
echo ""
echo $'\e[0m\e[1;36m[\e[1;37m01\e[0m\e[0m\e[1;36m]\e[0m \e[0m\e[1;33mstatus\e[0m'
echo $'\e[0m\e[1;36m[\e[1;37m02\e[0m\e[0m\e[1;36m]\e[0m \e[0m\e[1;33mstatus numbered\e[0m'
echo $'\e[0m\e[1;36m[\e[1;37m03\e[0m\e[0m\e[1;36m]\e[0m \e[0m\e[1;33mstatus verbose\e[0m'
echo ""
read -p $'\e[1;36m[*]\e[1m \e[1;37mChoose an option:\e[1m ' statusOption
if [[ $statusOption == 1 || $statusOption == 01 ]];
then
echo ""
sudo ufw status
read -s -p $'\e[1;36m Press <Enter> to return or Ctrl + c to exit\e[1m' finalOption
if [[ $finalOption = 'exit' || $finalOption = 'EXIT' || $finalOption = 'Exit' ]];
then
echo ""
exit
else
sleep 0
clear && ./netportcontrol.sh
fi
elif [[ $statusOption == 2 || $statusOption == 02 ]];
then
echo ""
sudo ufw status numbered
read -s -p $'\e[1;36m Press <Enter> to return or Ctrl + c to exit\e[1m' finalOption
if [[ $finalOption = 'exit' || $finalOption = 'EXIT' || $finalOption = 'Exit' ]];
then
echo ""
exit
else
sleep 0
clear && ./netportcontrol.sh
fi
elif [[ $statusOption == 3 || $statusOption == 03 ]];
then
echo ""
sudo ufw status verbose
read -s -p $'\e[1;36m Press <Enter> to return or Ctrl + c to exit\e[1m' finalOption
if [[ $finalOption = 'exit' || $finalOption = 'EXIT' || $finalOption = 'Exit' ]];
then
echo ""
exit
else
sleep 0
clear && ./netportcontrol.sh
fi
else
echo ""
echo $'\e[1;31m [*] Invalid option!\e[1m'
sleep 1
clear && ./netportcontrol.sh
fi
elif [[ $option == 4 || $option == 04 ]];
then
echo ""
read -p $'\e[1;36mDo you want enable UFW ? [Y/n]:\e[1m ' confirm
if [[ $confirm = Y || $confirm = y ]];
then
sudo ufw enable
echo ""
read -s -p $'\e[1;36m Press <Enter> to return or Ctrl + c to exit\e[1m' finalOption
if [[ $finalOption = 'exit' || $finalOption = 'EXIT' || $finalOption = 'Exit' ]];
then
echo ""
exit
else
sleep 0
clear && ./netportcontrol.sh
fi
elif [[ $confirm = n || $confirm = N ]];
then
echo ""
read -s -p $'\e[1;36m Press <Enter> to return or Ctrl + c to exit\e[1m' finalOption
if [[ $finalOption = 'exit' || $finalOption = 'EXIT' || $finalOption = 'Exit' ]];
then
echo ""
exit
else
sleep 0
clear && ./netportcontrol.sh
fi
else
echo ""
echo $'\e[1;31m [*] Invalid option!\e[1m'
sleep 1
clear && ./netportcontrol.sh
fi
elif [[ $option == 5 || $option == 05 ]];
then
echo ""
read -p $'\e[1;36mDo you want disable UFW ? [Y/n]:\e[1m ' confirm
if [[ $confirm = Y || $confirm = y ]];
then
sudo ufw disable
echo ""
read -s -p $'\e[1;36m Press <Enter> to return or Ctrl + c to exit\e[1m' finalOption
if [[ $finalOption = 'exit' || $finalOption = 'EXIT' || $finalOption = 'Exit' ]];
then
echo ""
exit
else
sleep 0
clear && ./netportcontrol.sh
fi
elif [[ $confirm = n || $confirm = N ]];
then
echo ""
read -s -p $'\e[1;36m Press <Enter> to return or Ctrl + c to exit\e[1m' finalOption
if [[ $finalOption = 'exit' || $finalOption = 'EXIT' || $finalOption = 'Exit' ]];
then
echo ""
exit
else
sleep 0
clear && ./netportcontrol.sh
fi
else
echo ""
echo $'\e[1;31m [*] Invalid option!\e[1m'
sleep 1
clear && ./netportcontrol.sh
fi
elif [[ $option == 6 || $option == 06 ]];
then
echo ""
read -p $'\e[1;36mDo you want reload UFW ? [Y/n]:\e[1m ' confirm
if [[ $confirm = Y || $confirm = y ]];
then
sudo ufw reload
elif [[ $confirm = n || $confirm = N ]];
then
echo ""
echo $'\e[1;33mExiting ...\e[1m'
exit
fi
elif [[ $option == 7 || $option == 07 ]];
then
echo ""
read -p $'\e[1;36mDo you want reset UFW ? [Y/n]:\e[1m ' confirm
if [[ $confirm = Y || $option = y ]];
then
sudo ufw reset
elif [[ $confirm = n || $option = N ]];
then
echo ""
echo $'\e[1;33mExiting ...\e[1m'
exit
fi
elif [[ $option == 8 || $option == 08 ]];
then
echo ""
echo $'\e[0m\e[1;36m[\e[1;37m01\e[0m\e[0m\e[1;36m]\e[0m \e[0m\e[1;33minstall UFW\e[0m'
echo $'\e[0m\e[1;36m[\e[1;37m02\e[0m\e[0m\e[1;36m]\e[0m \e[0m\e[1;33muninstall UFW\e[0m'
echo $'\e[0m\e[1;36m[\e[1;37m03\e[0m\e[0m\e[1;36m]\e[0m \e[0m\e[1;33mdelete rule\e[0m'
echo ""
read -p $'\e[1;36m[*]\e[1m \e[1;37mChoose an option:\e[1m ' ufwOption
if [[ $ufwOption == 1 || $ufwOption == 01 ]];
then
echo ""
read -p $'\e[1;36mDo you want install UFW ? [Y/n]:\e[1m ' confirm
fi
if [[ $confirm = Y || $confirm = y ]];
then
sudo apt-get install ufw -y
elif [[ $confirm = n || $confirm = N ]];
then
echo ""
echo $'\e[1;33mExiting ...\e[1m'
exit
fi
if [[ $ufwOption == 2 || $ufwOption == 02 ]];
then
echo ""
read -p $'\e[1;36mDo you want uninstall UFW ? [Y/n]:\e[1m ' confirm
if [[ $confirm = Y || $confirm = y ]];
then
sudo apt-get remove --purge ufw -y
elif [[ $confirm = n || $confirm = N ]];
then
echo ""
echo $'\e[1;33mExiting ...\e[1m'
exit
fi
fi
if [[ $ufwOption == 3 || $ufwOption == 03 ]];
then
echo $'\e[1;37m\e[1m'
sudo ufw status numbered
echo ""
read -p $'\e[1;36m[*]\e[1m \e[1;37mWhich rule you want delete?: \e[1m' ruleOption
sudo ufw delete $ruleOption
fi
elif [[ $option == 9 || $option == 09 || $option = 'exit' || $option = 'EXIT' ]];
then
echo ""
echo $'\e[1;33mExiting ...\e[1m'
exit
else
echo ""
echo $'\e[1;31m [*] Invalid option!\e[1m'
sleep 1
clear && ./netportcontrol.sh
fi