#!/bin/sh output_as_proxychains=1 randomize=1 choose=0 outputted_proxies="" temp_output=$(mktemp) while getopts ":pt:rc:" options; do case $options in p) output_as_proxychains=0 ;; t) temp_output=$OPTARG ;; r) randomize=0 ;; c) choose=$OPTARG ;; :) printf "specify argument\n" exit ;; *) printf "what has happened\n" exit ;; esac done # get the tor port number using this lsof incantination torport=$(\ sudo lsof -nP -iTCP -sTCP:LISTEN | \ grep tor | \ awk -F'[ :]+' 'NR = 1 {print $10}' ) curl --silent --preproxy socks5://127.0.0.1:$torport https://raw.githubusercontent.com/hookzof/socks5_list/master/proxy.txt -o $temp_output printf "estimated worsecase run time: %i seconds\n" $(wc -l $temp_output | awk -F' ' '{print $1}') 1>&2 looped=$(\ cat $temp_output | \ ( [ $randomize -eq 0 ] && shuf || cat ) | \ ( [ $choose -ne 0 ] && head -n $choose || cat ) | \ tr '\n' ' ' | \ tr -d '\r' ) for i in $looped; do ip=$(printf $i | awk -F':' '{print $1}') port=$(printf $i | awk -F':' '{print $2}' | tr -d '\r') # TODO: timeout is a non-posix gnu extension, remove/replace it timeout 2s nc -zv -x 127.0.0.1:$torport $ip $port 2>/dev/null 1>&2 && \ outputted_proxies="$outputted_proxies $i" && \ printf "success! %s\n" $i 1>&2 || \ printf "failure! %s\n" $i 1>&2 done if [ $output_as_proxychains -eq 0 ]; then printf "# generated by proxtest.sh @ %s\n" "$(date)" printf "random_chain\nproxy_dns\nchain_len = 5\n" printf "tcp_read_time_out 15000\ntcp_connect_time_out 8000\n" printf "[ProxyList]\n" # assumes all socks5 proxies, change this in future for i in $outputted_proxies; do printf "socks5 %s\n" "$(printf %s $i | tr ':' ' ')" done printf "# finished!\n" else for i in $outputted_proxies; do printf "%s\n" $i done fi