Proxy verifier in Bash script

I have a list of proxies and I need to verify if they are good to be used.

I looked online and I found some options: Proprietary softwares that typically has a license fee; Web services that might store the information and use it elsewhere; Open-source tools that need a lot of effort just to install. I just want something cheap and fast so I thought, yeah, might be few lines of Bash script would do this just fine.

#!/bin/bash

proxy_input="./proxy_list.txt"
export proxy_output="./proxy_list_ok.txt"
export timeout=10
export protocol="socks5"

proxy_verifier()
{
    read -r proxy <<<"${1//[$'\t\r\n']}"
    response=$(curl --insecure --connect-timeout ${timeout} --proxy "${protocol}://"${proxy} --silent --url "http://azenv.net")
    if [ "$?" -eq 0 ]; then
        if [[ ! $response =~ "$2" ]] && [[ $response =~ "PHP Proxy Judge" ]]; then
            echo $1 >> "${proxy_output}"
        fi
    fi
}

public_ip=$(curl --silent --url "http://ipinfo.io/ip")

export -f proxy_verifier
parallel -j 32 --bar --progress --eta proxy_verifier :::: "${proxy_input}" ::: "${public_ip}"

The first is to put list of the proxies in a file named proxy_list.txt, one proxy per line:

10.1.1.1:1080
172.16.1.1:12345
192.168.1.1:9999

Then the script will

  1. Get the public IP address of the machine running the script (this is to later verify if the proxy server leaks the IP address of the user)
  2. Use parallel to loop through file line by line and verify the proxies, with up to 32 jobs can be running in parallel at the same time for faster processing
  3. For each proxy, the script will use curl to connect to the proxy and make a request to a proxy judge website. If the proxy is good then it will be put into another file named proxy_list_ok.txt

The script can be modified for more advanced features such as automatic detection proxy protocol, retrieve geolocation information of the proxy or determine the speed. But for now it is all that I need.

Viet

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments