Unblock Websites
  • 16 Jan 2025
  • 2 読む分
  • PDF

Unblock Websites

  • PDF

The content is currently unavailable in Ja - 日本語. You are viewing the default English version.
記事の要約

Use this script to unblock the websites defined in the script, that may have been blocked using the block websites script.

  1. Copy and save the contents below to a UTF-8 editor like notepad++ OR Sublime Text in Windows or gedit in Ubuntu.

    1. If you are using notepad++ then use the bottom right panel to change the type to Unix (LF).

  2. Click here to download the file.

    #!/bin/bash
    
    # Function to check if the script is running as root
    check_root() {
        if [ "$(id -u)" -ne 0 ]; then
            echo "Please run this script as root or using sudo."
            exit 1
        fi
    }
    
    # Function to create a backup of the /etc/hosts file
    backup_hosts_file() {
        cp /etc/hosts /etc/hosts.bak
        if [ $? -ne 0 ]; then
            echo "Failed to create a backup of /etc/hosts. Exiting."
            exit 1
        fi
        echo "Backup of /etc/hosts created at /etc/hosts.bak."
    }
    
    # Function to unblock websites
    unblock_websites() {
        websites=("facebook.com" "youtube.com" "mail.google.com")
    
        for website in "${websites[@]}"; do
            # Check if the website is present in the /etc/hosts file
            if grep -q "$website" /etc/hosts; then
                # Remove the website entry from the /etc/hosts file
                sed -i "/$website/d" /etc/hosts
                if [ $? -eq 0 ]; then
                    echo "$website unblocked successfully."
                else
                    echo "Error: Failed to unblock $website."
                fi
            else
                echo "No entry found for $website in /etc/hosts."
            fi
        done
    }
    
    # Function to verify changes and notify the user
    verify_changes() {
        # Compare the original and modified files to confirm changes
        if cmp -s /etc/hosts /etc/hosts.bak; then
            echo "No changes were made to unblock websites."
        else
            echo "Websites unblocked successfully."
        fi
    }
    
    # Main Script Execution
    check_root        # Ensure the script is run as root
    backup_hosts_file  # Create a backup of the /etc/hosts file
    unblock_websites  # Unblock websites from the /etc/hosts file
    verify_changes    # Verify if changes were made and notify the user
  3. In the script, insert the URLs to be unblocked against the placeholder:

    1. unblock_websites() {

         websites=

    2. For example,

      unblock_websites() {
          websites=("facebook.com" "youtube.com" "mail.google.com")
  4. Follow our guide to upload & publish the script using Scalefusion Dashboard.

Note:

  1. Some of the scripts and their contents are sourced from internet and yes, our new friend ChatGPT.

  2. Please validate the scripts on a test machine before deploying them on all your managed devices.

  3. Scalefusion has tested these scripts, however Scalefusion will not be responsible for any loss of data or system malfunction that may arise due to the usage of these scripts.


この記事は役に立ちましたか?