public static function chech_proxy($proxy)

 


    public static function chech_proxy($proxy) {

        if (str_contains($proxy , '@')) {

            $ip_arry = explode("@",$proxy );

            $proxy_userpass = $ip_arry[0]; // "$username:$password"

            $proxy_ip = $ip_arry[1]; // "$ip:$pot"

            // $url = "https://api.ipify.org"; // Example URL to test the proxy (returns your public IP)

            $url = "http://www.cpanel.net/showip.cgi"; // Example URL to test the proxy (returns your public IP)


            try {

                $types = [

                    CURLPROXY_HTTP => "HTTP",

                    CURLPROXY_SOCKS5 => "SOCKS5",

                ];

                $index = 0; // Initialize a counter


                foreach ($types as $type => $typeName) {

                    // Initialize cURL

                    $ch = curl_init();

                    curl_setopt($ch, CURLOPT_URL, $url);

                    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

                    // Set the proxy address and port

                    curl_setopt($ch, CURLOPT_PROXY, $proxy_ip);

                    // Set the proxy credentials (username:password)

                    curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxy_userpass);

                    // Specify the proxy type (choose based on your proxy type)

                    curl_setopt($ch, CURLOPT_PROXYTYPE, $type); // For SOCKS5

                    // curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP); // For HTTP proxy

                    // Optional: Add timeout to handle unresponsive proxies

                    curl_setopt($ch, CURLOPT_TIMEOUT, 15);

                    // Execute the cURL request

                    $response = curl_exec($ch);

                    $curlError = curl_error($ch);

                    if ($index == 0){

                        $index++;

                        if (!curl_errno($ch)) {

                            curl_close($ch);

                            return [1, ""];

                            // break;

                        }

                    }else{

                        if (!curl_errno($ch)) {

                            curl_close($ch);

                            return [1, ""];

                            // break;

                        }else{

                            return [0,$curlError];

                        }

                    }


                }


            }catch(Exception $e) {

                return [2, $e->getMessage()];

            }



        }else{

            try {

                $ch = curl_init ();

                curl_setopt ($ch, CURLOPT_URL, "http://www.cpanel.net/showip.cgi");

                curl_setopt ($ch, CURLOPT_TIMEOUT, 10);

                curl_setopt ($ch, CURLOPT_PROXY, trim($proxy));

                curl_setopt ($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);

                curl_setopt ($ch, CURLOPT_RETURNTRANSFER, TRUE);

                $result = curl_exec($ch);

                $curlError = curl_error($ch);

                if($result!==FALSE){

                    return [1,$curlError];

                }else{

                    return [0,$curlError];

                }

                curl_close ($ch);


            }catch(Exception $e) {

                return [2, $e->getMessage()];

            }

        }



    }


Post a Comment

أحدث أقدم