Борба с досадните реклами.

Задавайте Вашите въпроси за Help and Support относно всички версии на операционната система тук.
Публикувай отговор
Аватар
admin
Site Admin
Site Admin
Мнения: 3580
Регистриран на: Съб Май 11, 2002 9:43 am
skype: john.doe.12
Местоположение: Earth
Обратна връзка:

Борба с досадните реклами.

Мнение от admin »

На всички линукс потребители мога да предложа едно малко скриптче което днеска дооправих за борба с рекламите. Какво прави то:
Когато искате да отворите дадена страница вашата кошница проверява дали съответния сървър вече го има в /etc/hosts файла и ако е така взема ИП адреса от там, ако го няма пита вашия DNS сървър. Скрипта на практика събира от 4 сайта информацията за рекламите и променя вашия hosts файл като добавя вашите записи който си имате. Стартирайте под роот.
Препоръчвам ви го в комбинация с Mozilla Adblock Plus

#cat /usr/bin/updatehosts.sh

Код за потвърждение: Избери целия код

#!/bin/bash
# Hosts file updater
# You will probably need root or su rights to access /etc/hosts
# modified by Condor
#
# Debian users will need the package "sysutils"
# $ sudo apt-get install sysutils
#
HFSERVER="http://hostsfile.mine.nu.nyud.net"
HFILE="hosts.zip"
ORIGFILE="/etc/hosts.original"

HFSERVER1="http://www.mvps.org/winhelp2002"
HFSERVER2="http://everythingisnt.com"
HFILE2="hosts"
HFSERVER3="http://pgl.yoyo.org/as"
HFILE3="serverlist.php?hostformat=hosts&showintro=1&mimetype=plaintext"
HFSERVER4="http://www.hosts-file.net/download"
TEMPH="/tmp/temp.hosts"

clear
echo "-------------------------------------------------------------"
echo "This script will update your Hosts file to the latest version"
echo "Your original Hosts file will be renamed to $ORIGFILE"
echo "-------------------------------------------------------------"
echo ""

if [ ! -f "$ORIGFILE" ] ; then
  echo "Backing up your previous hosts file.." 
  cp -v /etc/hosts $ORIGFILE # I like verbose file operations.  Can be less verbose if necessary.
fi

echo "Preparing for download and delete old files"
if [ -f "/tmp/HOSTS" ]; then
  rm /tmp/HOSTS
fi
if [ -f "/tmp/hosts.zip" ]; then
  rm /tmp/hosts.zip
fi
if [ -f "/tmp/hosts" ]; then
  rm /tmp/hosts
fi
if [ -f "/tmp/HOSTS.txt" ]; then
  rm /tmp/hosts
fi
if [ -f "/tmp/hosts.new" ]; then
  rm /tmp/hosts.new
fi
if [ -f "/tmp/temp.hosts" ]; then
  rm /tmp/temp.hosts
fi


echo "Retrieving $HFILE from $HFSERVER"
echo ""
wget -O /tmp/$HFILE $HFSERVER/$HFILE
unzip -p /tmp/$HFILE | sed "s/\r//g" > /tmp/hosts
if [ 'grep -c "banner" /tmp/hosts' ]; then
    echo "Downloaded and unpacked $HFILE OK"
    echo "Appending host list to original content"  # which was probably there for a reason, like to make sure localhost worked, and possibly even more stuff if part of a corporate LAN
    #cp -f -u /tmp/hosts /etc/hosts
#    cat $ORIGFILE > $TEMPH
#    echo "" >> $TEMPH # to make sure the original file ends in a new-line so that 2 entries don't end up on the same line, either causing unexpected behavior or not working at all
    cat /tmp/hosts > $TEMPH
    rm -fv /tmp/hosts* # again, I like verbose file operations.  I like to know what my system is doing.
    echo "Update process complete"
    #echo "-------------------------------------------------------------"
    echo "As a side-effect of this script, any changes you wish to make"
    echo "persistent in the hosts file should be made to $ORIGFILE"
    echo "because /etc/hosts will be respawned from that file and the "
    echo "newlist from the server each time this script runs."
else
    echo "Update failed"
fi

echo ""
echo "Retrieving $HFILE from $HFSERVER1"
echo ""
wget -O /tmp/$HFILE $HFSERVER1/$HFILE
unzip -p /tmp/$HFILE HOSTS | sed "s/\r//g" > /tmp/hosts
echo "Downloaded and unpacked $HFILE OK"
echo "Appending host list to original content"
echo "" >> $TEMPH # to make sure the original file ends in a new-line so that 2 entries don't end up on the same line, either causing unexpected behavior or not working at all
cat /tmp/hosts >> $TEMPH
rm -fv /tmp/hosts* # again, I like verbose file operations.  I like to know what my system is doing.
echo "Update process complete"
echo "-------------------------------------------------------------"

echo ""
echo "Retrieving $HFILE2 from $HFSERVER2"
echo ""
wget -O /tmp/$HFILE2 $HFSERVER3/$HFILE3
cat /tmp/$HFILE2 | sed "s/\r//g" > /tmp/hosts
echo "Downloaded and unpacked $HFILE OK"
echo "Appending host list to original content"
echo "" >>/etc/hosts # to make sure the original file ends in a new-line so that 2 entries don't end up on the same line, either causing unexpected behavior or not working at all
cat /tmp/hosts >> $TEMPH
rm -fv /tmp/hosts* # again, I like verbose file operations.  I like to know what my system is doing.
echo "Update process complete"
echo "-------------------------------------------------------------"

echo ""
echo "Retrieving $HFILE2 from $HFSERVER3"
echo ""
wget -O /tmp/$HFILE2 $HFSERVER3/$HFILE3
cat /tmp/$HFILE2 | sed "s/\r//g" > /tmp/hosts
echo "Downloaded and unpacked $HFILE OK"
echo "Appending host list to original content"
echo "" >>/etc/hosts # to make sure the original file ends in a new-line so that 2 entries don't end up on the same line, either causing unexpected behavior or not working at all
cat /tmp/hosts >>/etc/hosts
rm -fv /tmp/hosts* # again, I like verbose file operations.  I like to know what my system is doing.
echo "Update process complete"
echo "-------------------------------------------------------------"

echo ""
echo "Retrieving $HFILE from $HFSERVER4"
echo ""
wget -U="" -O /tmp/$HFILE $HFSERVER4/$HFILE
unzip -p /tmp/$HFILE HOSTS.txt | sed "s/\r//g" > /tmp/hosts
echo "Downloaded and unpacked $HFILE OK"
echo "Appending host list to original content"
echo "" >>/etc/hosts # to make sure the original file ends in a new-line so that 2 entries don't end up on the same line, either causing unexpected behavior or not working at all
cat /tmp/hosts >> $TEMPH
rm -fv /tmp/hosts* # again, I like verbose file operations. I like to know what my system is doing.
echo "Update process complete"
echo "-------------------------------------------------------------"

echo ""
echo "Analysing file..."
awk -F'\t' '{print $1, $2}' $TEMPH > /tmp/hosts.new
cat /tmp/hosts.new | sed '/^\#/d' > $TEMPH
awk -F'  ' '{print $1, $2}' $TEMPH > /tmp/hosts.new
awk '{print $1, $2}' /tmp/hosts.new > $TEMPH
mv $TEMPH /tmp/hosts.new
echo "Sorting unique host names"
sort -u < /tmp/hosts.new > /etc/hosts
cat $ORIGFILE > $TEMPH
cat /etc/hosts >> $TEMPH
mv $TEMPH /etc/hosts
echo "Installation complete."
"There is no 'patch' for stupidity."
Публикувай отговор