#!/bin/bash# URL of the porn blocklist (StevenBlack)BLOCKLIST_URL="https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/porn-only/hosts"# Temp file to hold the downloaded blocklistTEMP_BLOCKLIST="/tmp/porn-blocklist.hosts"# Backup current /etc/hostsecho "[*] Backing up current /etc/hosts to /etc/hosts.backup"sudo cp /etc/hosts /etc/hosts.backup# Download blocklistecho "[*] Downloading porn blocklist..."curl -sSL "$BLOCKLIST_URL" -o "$TEMP_BLOCKLIST"# Extract only the valid blocking lines (ignore comments and blank lines)BLOCK_ENTRIES=$(grep -E "^(0.0.0.0|127.0.0.1) " "$TEMP_BLOCKLIST")# Append to /etc/hostsecho "[*] Appending blocklist to /etc/hosts"echo -e "\n# BEGIN PORN BLOCKLIST ($(date))" | sudo tee -a /etc/hosts > /dev/nullecho "$BLOCK_ENTRIES" | sudo tee -a /etc/hosts > /dev/nullecho "# END PORN BLOCKLIST" | sudo tee -a /etc/hosts > /dev/null# Flush DNS cacheecho "[*] Flushing DNS cache..."sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder# Make /etc/hosts immutableecho "[*] Locking /etc/hosts to prevent edits"sudo chflags schg /etc/hostsecho "[✅] Porn sites blocked and hosts file locked."echo "[!] To unlock it in the future, use:"echo " sudo chflags noschg /etc/hosts"
block-porn.zsh
#!/bin/zsh# URL of the porn blocklist (StevenBlack)BLOCKLIST_URL="https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/porn-only/hosts"# Temp file to hold the downloaded blocklistTEMP_BLOCKLIST="/tmp/porn-blocklist.hosts"# Backup current /etc/hostsecho "[*] Backing up current /etc/hosts to /etc/hosts.backup"sudo cp /etc/hosts /etc/hosts.backup# Download blocklistecho "[*] Downloading porn blocklist..."curl -sSL "$BLOCKLIST_URL" -o "$TEMP_BLOCKLIST"# Extract only the valid blocking lines (ignore comments and blank lines)BLOCK_ENTRIES=$(grep -E "^(0.0.0.0|127.0.0.1) " "$TEMP_BLOCKLIST")# Append to /etc/hostsecho "[*] Appending blocklist to /etc/hosts"echo "\n# BEGIN PORN BLOCKLIST ($(date))" | sudo tee -a /etc/hosts > /dev/nullecho "$BLOCK_ENTRIES" | sudo tee -a /etc/hosts > /dev/nullecho "# END PORN BLOCKLIST" | sudo tee -a /etc/hosts > /dev/null# Flush DNS cacheecho "[*] Flushing DNS cache..."sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder# Make /etc/hosts immutableecho "[*] Locking /etc/hosts to prevent edits"sudo chflags schg /etc/hostsecho "[✅] Porn sites blocked and hosts file locked."echo "[!] To unlock it in the future, use:"echo " sudo chflags noschg /etc/hosts"