Created
June 21, 2023 08:52
-
-
Save jpenalbae/6b9d5d9af5bdc8d6c55fa363aebfbede to your computer and use it in GitHub Desktop.
Simple proxy tester with multi-threading support using bash and curl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Simple proxy tester with multi-threading support. | |
# Tests socks4, socks5, and http proxies. | |
# | |
# Usage: ./proxy_tester.sh [protocol] [proxy_list] [nthread] [url] [timeout] | |
# Example: ./proxy_tester.sh http proxies.txt 10 https://www.google.com/ 5 | |
# Set default values for test URL and timeout | |
TEST_URL="https://www.strava.com/" | |
TIMEOUT=5 | |
# Function to test a single proxy | |
function test_proxy() { | |
local proxy=$1 | |
local protocol=$2 | |
local timeout=$3 | |
# Test the proxy by sending a request to the test URL | |
local response=$(curl -s -w '%{http_code},%{time_total}' -o /dev/null -x $protocol://$proxy --connect-timeout $timeout ${TEST_URL}) | |
# Extract the HTTP code and response time from the response | |
HTTP_CODE=$(echo $response | cut -d',' -f1) | |
TIME=$(echo $response | cut -d',' -f2) | |
# Print a message if the proxy is working | |
if [[ $HTTP_CODE == 200 ]]; then | |
echo "Proxy $proxy is working. Response time: $TIME seconds." | |
fi | |
} | |
# Function to display usage information | |
function usage() { | |
echo "Usage: $0 [protocol] [proxy_file] [num_threads] [test_url] [timeout]" | |
echo "Example: $0 http proxies.txt 10 https://www.google.com/ 10" | |
} | |
# Check if all arguments are provided | |
if [[ $# -lt 3 ]]; then | |
usage | |
exit 1 | |
fi | |
# Assign arguments to variables | |
protocol=$1 | |
proxy_file=$2 | |
num_threads=$3 | |
# Validate protocol | |
if [[ $protocol != http && $protocol != socks4 && $protocol != socks5 ]]; then | |
echo "Invalid protocol. Only http, socks4, and socks5 protocols are supported." | |
exit 1 | |
fi | |
# Check if test URL and timeout are provided | |
if [[ $# -ge 4 ]]; then | |
TEST_URL=$4 | |
fi | |
if [[ $# -ge 5 ]]; then | |
TIMEOUT=$5 | |
fi | |
# Read proxy file and test each proxy | |
count=0 | |
while IFS= read -r proxy; do | |
test_proxy "$proxy" "$protocol" ${TIMEOUT} & | |
((count++)) | |
if [[ $count -eq num_threads ]]; then | |
wait | |
count=0 | |
fi | |
done < "$proxy_file" | |
wait | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment