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:
This script performs the following tasks:
curl
with the generated IP and User-Agent.#!/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
pkg install curl
nano random_request.sh
chmod +x random_request.sh
./random_request.sh
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.
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.