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.
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.
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.
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."
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.
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.
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.
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.
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.
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.
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.
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.
generate_random_ipv4
: Generates a random IPv4 address.generate_random_ipv6
: Generates a random IPv6 address.generate_random_user_agent
: Chooses a random user-agent string from a predefined list.get_random_keyword
: Picks a random keyword from the list of search keywords.perform_search_and_process_links
: Conducts a Google search for a keyword, processes the search results to extract links, fetches the content of each link, and measures the response time.while true; do ... done
: Ensures the script runs indefinitely. Inside this loop, the script:
perform_search_and_process_links
to search and process links related to that keyword.curl
.This process will continue running until manually stopped (e.g., by pressing Ctrl + C
in the terminal).