-
Notifications
You must be signed in to change notification settings - Fork 0
/
block_websites.sh
48 lines (42 loc) · 1.93 KB
/
block_websites.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
#!/bin/bash
if [ "$(id -u)" != "0" ]; then
echo "This script must be run as root" 1>&2
exit 1
fi
arr=('linkedin.com' 'twitch.tv' 'instagram.com' 'facebook.com' 'twitter.com' 'twttr.com' 'twitter.fr' 'twitter.jp' 'twitter.rs' 'twitter.uz' 'twitter.biz' 'twitter.dk' 'twitter.events' 'twitter.ie' 'twitter.je' 'twitter.mobi' 'twitter.nu' 'twitter.pro' 'twitter.su' 'twitter.vn' 'twitter.com' 'twitter.gd' 'twitter.im' 'twitter.hk' 'twitter.jp' 'twitter.ch' 'twitter.pt' 'twitter.rs' 'twitter.com.br' 'twitter.ae' 'twitter.eus' 'ns1.p34.dynect.net' 'ns2.p34.dynect.net' 'ns3.p34.dynect.net' 'ns4.p34.dynect.net' 'd01-01.ns.twtrdns.net' 'd01-02.ns.twtrdns.net' 'a.r06.twtrdns.net' 'b.r06.twtrdns.net' 'c.r06.twtrdns.net' 'api-34-0-0.twitter.com' 'api-47-0-0.twitter.com' 'cheddar.twitter.com' 'goldenglobes.twitter.com' 'mx003.twitter.com' 'pop-api.twitter.com' 'spring-chicken-an.twitter.com' 'spruce-goose-ae.twitter.com' 'takeflight.twitter.com' 'www2.twitter.com')
function update_script() {
local action=$1
local website=$2
local script_name=$3
if [ "$action" == "add" ]; then
sed -i "s/^arr=(/&'$website' /" $script_name
elif [ "$action" == "remove" ]; then
sed -i "s/'$website' //g" $script_name
fi
}
if [ $1 == "on" ]
then
for i in "${arr[@]}"
do
echo 0.0.0.0 www.$i >> /etc/hosts
echo 0.0.0.0 $i >> /etc/hosts
echo 0.0.0.0 m.$i >> /etc/hosts
echo 0.0.0.0 mobile.$i >> /etc/hosts
echo fe80::1%lo0 www.$i >> /etc/hosts
echo fe80::1%lo0 $i >> /etc/hosts
echo fe80::1%lo0 m.$i >> /etc/hosts
echo fe80::1%lo0 mobile.$i >> /etc/hosts
done
elif [ $1 == "off" ]
then
sed -i '/0.0.0.0/d' /etc/hosts
sed -i '/fe80::1%lo0/d' /etc/hosts
elif [ $1 == "add" ]
then
update_script "add" "$2" "$0"
elif [ $1 == "remove" ]
then
update_script "remove" "$2" "$0"
else
echo "Invalid command. Usage: $0 [on|off|add|remove] [website]"
fi