-
Notifications
You must be signed in to change notification settings - Fork 0
/
swdns
executable file
·87 lines (76 loc) · 2.14 KB
/
swdns
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
#!/bin/bash
#
# Author: Akhid Yanuar A.F (https://github.com/yanuarakhid)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
BACKUP=1
pause(){
read -p "Press [Enter] key to continue..." fackEnterKey
}
set_localhost(){
clear
echo "Set nameserver to 127.0.0.1"
echo "nameserver 127.0.0.1" > /etc/resolv.conf
echo -e "\e[32mSUCCESS\e[0m"
exit
}
reset(){
echo "Reset resolv.conf with backup file"
mv /etc/resolv.conf.default /etc/resolv.conf
sed -i '20s/BACKUP=2/BACKUP=1/' swdns
echo -e "\e[32mRESET SUCCESS\e[0m"
exit
}
set_manual(){
clear
read -p "Input The DNS server you want : " manual_set
echo "nameserver" $manual_set > /etc/resolv.conf
echo -e "\e[32mSUCCESS\e[0m"
exit
}
show_menus() {
clear
echo "============================="
echo -e " \e[5m- SWDNS -\e[25m"
echo "github.com/yanuarakhid/swdns"
echo "============================="
echo -e "\e[33m[1.] Set DNS to localhost (127.0.0.1)\e[39m"
echo -e "\e[34m[2.] Manual Set\e[39m"
echo -e "\e[32m[3.] Reset To Default resolv.conf\e[39m"
echo -e "\e[31m[4.] Exit\e[39m"
}
read_options(){
local choice
read -p "Enter choice [ 1 - 3] " choice
case $choice in
1) set_localhost ;;
2) set_manual ;;
3) reset ;;
4|q) exit 0;;
*) echo -e "${RED}Invalid Input Option ${choice} ...${STD}" && sleep 1
esac
}
trap '' SIGINT SIGQUIT SIGTSTP
if [ $BACKUP == 1 ]
then
echo "Creating resolv.conf backup files...." && sleep 1
cp /etc/resolv.conf /etc/resolv.conf.default
sed -i '20s/BACKUP=1/BACKUP=2/' swdns
fi
while true
do
show_menus
read_options
done