Bash Script Execution Guide

Introduction

This guide provides instructions for running a Bash script that generates random IP addresses (both IPv4 and IPv6), User-Agent strings, and sends HTTP requests to a specified target URL using curl. The script runs in an infinite loop, sending a request every 2 seconds.

Estimated Reading Time:

Requirements

Script Explanation

This script performs the following tasks:

  1. Generates a random IPv4 or IPv6 address.
  2. Generates a random User-Agent string from a predefined list.
  3. Sends an HTTP request to the target URL using curl with the generated IP and User-Agent.
  4. Repeats the process every 2 seconds indefinitely.
#!/bin/bash

# Function to generate a random IPv4 address
generate_random_ipv4() {
    echo "$((RANDOM % 256)).$((RANDOM % 256)).$((RANDOM % 256)).$((RANDOM % 256))"
    # Explanation: This function generates four random numbers between 0 and 255,
    # concatenates them with dots to form an IPv4 address.
}

# 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)))"
    # Explanation: This function generates eight random hexadecimal numbers (each up to 4 digits),
    # and concatenates them with colons to form an IPv6 address.
}

# 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[@]}]}"
    # Explanation: This function randomly selects a User-Agent string from a predefined list.
}

# Target domain
target_url="https://www.miralishahidi.ir/"

while true; do
    # Randomly choose IPv4 or IPv6
    ip_version=$(( RANDOM % 2 ))

    if [ "$ip_version" -eq 0 ]; then
        ip_address=$(generate_random_ipv4)
    else
        ip_address=$(generate_random_ipv6)
    fi

    # Generate a random User-Agent
    user_agent=$(generate_random_user_agent)

    # Randomly select HTTP version (1.1 or 2)
    http_version=$(( RANDOM % 2 + 1 ))
    http_version_flag="--http1.1"
    if [ "$http_version" -eq 2 ]; then
        http_version_flag="--http2"
    fi

    echo "Sending request to $target_url with IP: $ip_address, User-Agent: $user_agent, HTTP version: $http_version"

    # Send the request
    curl -s -A "$user_agent" -H "X-Forwarded-For: $ip_address" $http_version_flag "$target_url" -o /dev/null

    echo "Request sent successfully"

    # Wait for 2 seconds before sending the next request
    sleep 2
done
        

Execution Instructions

  1. Open Termux on your Android device.
  2. Ensure `curl` is installed. If not, install it using the command:
    pkg install curl
  3. Create a new Bash script file using:
    nano random_request.sh
  4. Copy the provided script into the file and save it by pressing `CTRL + X`, then `Y`, and `Enter`.
  5. Make the script executable:
    chmod +x random_request.sh
  6. Run the script:
    ./random_request.sh

Additional Notes

Remember to monitor the script's execution to ensure it doesn't overwhelm the target server with too many requests, which could be considered malicious behavior.

Program Details

This Bash script is designed to help you understand how to generate and use random IP addresses and User-Agent strings for sending HTTP requests. It continuously sends requests to a target URL, which in this case is https://www.miralishahidi.ir. By simulating different IP addresses and User-Agents, you can test how a server handles various types of incoming requests. This can be useful for stress testing, simulating user behavior, or understanding how your server handles diverse client requests.