Termux Setup Guide with Script

Step 1: Update and Upgrade Termux Packages

First, you need to ensure that all the packages in Termux are up to date. Open Termux and run the following command:

pkg update && pkg upgrade

Explanation: This updates the package list to ensure Termux knows about the latest versions of available packages and then upgrades any installed packages to their latest versions. This ensures you have the latest features and security patches.

Step 2: Install Required Packages

Install the required packages like curl, bash, and bc by executing the command below:

pkg install curl bash bc

Explanation: Installs curl (a tool to transfer data from or to a server), bash (a Unix shell and command language), and bc (an arbitrary precision calculator language). These tools are necessary for the script to run properly.

Step 3: Create the Script File

Create a new file to hold your script using nano:

nano search_script.sh

Explanation: Opens the nano text editor to create a new file named search_script.sh where you will paste the script. nano allows you to write and edit text files directly in Termux.

Step 4: Paste the Script

Below is the Bash script that you'll be running. Copy it and paste it into the search_script.sh file you created:


#!/bin/bash

# Define the list of search keywords
keywords=(
    "IT" "ICT" "OT" "IIOT" "IOT" "network" "cybersecurity" "AI" "machine+learning" "data+science"
    "cloud+computing" "blockchain" "automation" "digital+transformation" "IoT" "big+data" 
    "analytics" "software+development" "IT+consulting" "networking" "virtualization" 
    "system+integration" "tech+trends" "IT+strategy" "smart+devices" "enterprise+IT" 
    "cyber+defense" "data+protection" "IT+infrastructure" "technology+solutions" 
    "security+services" "cloud+storage" "IT+support" "tech+innovation" "software+engineering" 
    "information+security" "IT+management" "digital+marketing" "IT+services" "enterprise+solutions" 
    "IT+architecture" "IT+operations" "mobile+computing" "IT+project+management" "IT+training" 
    "tech+consulting" "network+security" "IT+systems" "data+analytics" "IT+compliance" 
    "IT+governance" "IT+trends" "IT+support+services" "IT+outsourcing" "technology+consulting"
)

# Define the list of search engine referer templates
referer_templates=(
    "https://www.google.com/search?q="
    "https://www.bing.com/search?q="
    "https://search.yahoo.com/search?p="
    "https://duckduckgo.com/?q="
    "https://www.baidu.com/s?wd="
    "https://www.yandex.com/search/?text="
    "https://www.ask.com/web?q="
)

# Function to generate a random IPv4 address
generate_random_ipv4() {
    echo "$((RANDOM % 256)).$((RANDOM % 256)).$((RANDOM % 256)).$((RANDOM % 256))"
}

# Function to generate a random IPv6 address
generate_random_ipv6() {
    echo "$(printf '%x:%x:%x:%x:%x:%x:%x:%x' $(($RANDOM % 0xffff)) $(($RANDOM % 0xffff)) $(($RANDOM % 0xffff)) $(($RANDOM % 0xffff)) $(($RANDOM % 0xffff)) $(($RANDOM % 0xffff)) $(($RANDOM % 0xffff)) $(($RANDOM % 0xffff)))"
}

# Function to generate a random User-Agent string
generate_random_user_agent() {
    local user_agents=(
        "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"
        "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Edge/91.0.864.48 Safari/537.36"
        "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"
        "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Firefox/90.0"
        "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:90.0) Gecko/20100101 Firefox/90.0"
    )
    echo "${user_agents[$RANDOM % ${#user_agents[@]}]}"
}

# Function to generate a random referer based on the keyword
generate_random_referer() {
    local keyword="$1"
    local random_template="${referer_templates[$RANDOM % ${#referer_templates[@]}]}"
    echo "${random_template}${keyword}"
}

# Function to get a random keyword from the list
get_random_keyword() {
    echo "${keywords[$RANDOM % ${#keywords[@]}]}"
}

# Function to perform a search and process links
perform_search_and_process_links() {
    local keyword="$1"
    local search_url="https://www.google.com/search?q=${keyword}+site:miralishahidi.ir"
    
    # Randomly select HTTP version (1.1 or 2)
    local http_version=$(( RANDOM % 2 + 1 ))
    local http_version_flag="--http1.1"
    if [ "$http_version" -eq 2 ]; then
        http_version_flag="--http2"
    fi

    echo "Fetching page content from: $search_url with HTTP version: $http_version_flag"
    
    # Randomly generate User-Agent, IP, and Referer
    local user_agent=$(generate_random_user_agent)
    local referer=$(generate_random_referer "$keyword")
    local ip_version=$(( RANDOM % 2 ))
    local forwarded_ip
    if [ "$ip_version" -eq 0 ]; then
        forwarded_ip=$(generate_random_ipv4)
    else
        forwarded_ip=$(generate_random_ipv6)
    fi
    
    echo "Using X-Forwarded-For IP: $forwarded_ip"
    echo "Using Referer: $referer"
    
    # Fetch the page content with random headers
    page_content=$(curl -s -A "$user_agent" -H "X-Forwarded-For: $forwarded_ip" -H "Referer: $referer" $http_version_flag "$search_url")

    # Extract and clean up links
    echo "Extracting and cleaning up links..."
    echo "$page_content" | grep -oP '(?<=href="/url\?q=)[^"]*' | \
        sed 's/&/&/g' | \
        sed 's/%3A/:/g; s/%2F/\//g; s/%3F/?/g; s/%26/&/g; s/%2C/,/g; s/%2B/+/g; s/%20/ /g' | \
        awk -F'&' '{print $1}' | \
        sed 's/%20/ /g; s/%21/!/g; s/%2A/*/g; s/%28/(/g; s/%29/)/g; s/%7E/~/g; s/%2D/-/g' | \
        grep '\.html$' | while IFS= read -r link; do
            echo "Extracted link: $link"
            
            # Fetch the link content and measure time taken
            echo "Fetching content from: $link with HTTP version: $http_version_flag"
            
            start_time=$(date +%s.%N)
            response=$(curl -s -A "$user_agent" -H "X-Forwarded-For: $forwarded_ip" -H "Referer: $referer" $http_version_flag -w "%{http_code}" -o /tmp/link_content.html "$link")
            end_time=$(date +%s.%N)
            
            http_status=$(echo "$response" | tail -n 1)
            time_taken=$(echo "$end_time - $start_time" | bc)
            
            echo "HTTP Status Code: $http_status"
            echo "Time Taken: $time_taken seconds"
            
            echo "Link content preview:"
            head -n 10 /tmp/link_content.html
            
            echo "----------------------------------------"
            sleep $((RANDOM % 3 + 1))  # Random delay between requests (1 to 3 seconds)
        done
    
    echo "Link processing complete for keyword: $keyword"
}

# Main script execution

# Number of searches to perform
num_searches=5

# Perform searches and process links
echo "Starting Google searches and link processing..."
while true; do
    keyword=$(get_random_keyword)
    perform_search_and_process_links "$keyword"
    sleep 2  # Delay between searches
done

echo "All tasks completed."

Step 5: Make the Script Executable

To run the script, you need to make it executable. Run the following command:

chmod +x search_script.sh

Explanation: This command changes the file permissions of search_script.sh to make it executable, allowing it to be run as a program.

Step 6: Run the Script

Now, you can run the script by typing the following command:

./search_script.sh

Explanation: Executes the script, which will start running and continuously perform searches and process the links according to the defined logic.

Explanation of Script Execution

1. Update and Upgrade Termux Packages

Command: pkg update && pkg upgrade

Purpose: This updates the package list to ensure Termux knows about the latest versions of available packages and then upgrades any installed packages to their latest versions. This ensures you have the latest features and security patches.

2. Install Required Packages

Command: pkg install curl bash bc

Purpose: Installs curl (a tool to transfer data from or to a server), bash (a Unix shell and command language), and bc (an arbitrary precision calculator language). These tools are necessary for the script to run properly.

3. Create the Script File

Command: nano search_script.sh

Purpose: Opens the nano text editor to create a new file named search_script.sh where you will paste the script. nano allows you to write and edit text files directly in Termux.

4. Paste the Script

Action: Copy the provided script and paste it into the search_script.sh file opened with nano.

Purpose: The script contains the logic for performing Google searches and processing the links extracted from the search results. It includes functionality for generating random user agents, IP addresses, and handling HTTP requests.

5. Make the Script Executable

Command: chmod +x search_script.sh

Purpose: Changes the file permissions of search_script.sh to make it executable. This allows you to run the script as a program.

6. Run the Script

Command: ./search_script.sh

Purpose: Executes the script. The script will start running and continuously perform searches and process links according to the defined logic.

Explanation of Script Execution

1. Function Definitions:

2. Infinite Loop:

while true; do ... done: Ensures the script runs indefinitely. Inside this loop, the script:

Script Execution Flow:

  1. Start Loop: The script starts and enters the infinite loop.
  2. Keyword Selection: A random keyword is selected from the list.
  3. Search Execution: The script constructs a search URL using the selected keyword and performs a search using curl.
  4. HTTP Header Generation: Generates random HTTP headers, including User-Agent and X-Forwarded-For IP.
  5. Link Extraction: Processes the search results to extract and clean up links.
  6. Link Fetching: For each extracted link, fetches the content, measures response time, and prints HTTP status and a preview of the content.
  7. Delay: Waits for a random amount of time (1 to 3 seconds) before processing the next link.
  8. Repeat: The loop continues with a new keyword, repeating the search and processing steps indefinitely.

This process will continue running until manually stopped (e.g., by pressing Ctrl + C in the terminal).