Advertisement
metalx1000

Website Domain Blocker

Sep 4th, 2023
3,201
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.85 KB | None | 1 0
  1. #!/bin/bash
  2. ######################################################################
  3. #Copyright (C) 2023  Kris Occhipinti
  4. #https://filmsbykris.com
  5.  
  6. #This program is free software: you can redistribute it and/or modify
  7. #it under the terms of the GNU General Public License as published by
  8. #the Free Software Foundation version 3 of the License.
  9.  
  10. #This program is distributed in the hope that it will be useful,
  11. #but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. #GNU General Public License for more details.
  14.  
  15. #You should have received a copy of the GNU General Public License
  16. #along with this program.  If not, see <http://www.gnu.org/licenses/>.
  17. ######################################################################
  18.  
  19. url="https://filmsbykris.com/scripts/blocked_domains.lst"
  20.  
  21. function block(){
  22.  
  23.   wget -qO- "$url"|while read domain;
  24.   do
  25.     sudo iptables -A OUTPUT -p tcp -m string --string "$domain" --algo kmp -j REJECT
  26.   done
  27.   sudo iptables -L --line-numbers
  28.   exit
  29. }
  30.  
  31. function unblock(){
  32.   rule="$(sudo iptables -L --line-numbers|grep REJECT|fzf --prompt="Select a rule: "|awk '{print $1}')"
  33.   [[ $rule ]] || exit
  34.   sudo iptables -D OUTPUT $rule
  35.   sudo iptables -L --line-numbers                                                                                                              
  36.   exit
  37. }
  38.  
  39. function unblock_all(){
  40.   sudo iptables -L --line-numbers|grep "REJECT"|awk '{print $1}'|while read rule;do
  41.     sudo iptables -D OUTPUT 1
  42.   done
  43.   sudo iptables -L --line-numbers
  44.   exit
  45. }
  46.  
  47. function help(){
  48.   echo "
  49.  Options are:
  50.  unblock
  51.  all
  52.  show
  53.  help
  54.  block #default"
  55.   exit
  56. }
  57.  
  58. [[ "$1" == "unblock" ]] && unblock
  59. [[ "$1" == "all" ]] && unblock_all
  60. [[ "$1" == "show" ]] && sudo iptables -L --line-numbers
  61. [[ "$1" == "help" ]] && help
  62. block
  63.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement