-
Notifications
You must be signed in to change notification settings - Fork 0
/
tmphosts
38 lines (34 loc) · 1.08 KB
/
tmphosts
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
#!/bin/bash
#check file names before running
#if a file named /etc/hosts.temp already exists script will exit as it assumes the allowed hosts are running
#if no hosts allow file called /etc/hosts.bk exists it will be created
#amount of time measured in seconds for the hosts to be allowed
seconds=150
#do not edit after this line
minutes=`echo "scale=1; $seconds/60" | bc`
if [ -e /etc/hosts.bk ]
then
echo "Do nothing" > /dev/null
else
cat << EOF > /tmp/hosts.bk
127.0.0.1 localhost
127.0.1.1 afasfkjbasfasf
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
EOF
sed -i s/afasfkjbasfasf/`hostname`/g /tmp/hosts.bk && sudo mv /tmp/hosts.bk /etc/hosts.bk
fi
if [ -e /etc/hosts.temp ]
then
echo "hosts already unblocked" && exit
else
echo "Do nothing" > /dev/null
fi
sudo mv /etc/hosts /etc/hosts.temp
sudo cp /etc/hosts.bk /etc/hosts
echo "hosts unblocked for $minutes minutes"
sleep $seconds && sudo mv /etc/hosts.temp /etc/hosts&