public static function chech_proxy_1($proxy) {
// $ip_proxy = $proxy;
if (str_contains($proxy , '@')) {
$ip_arry = explode("@",$proxy );
$proxy_userpass = $ip_arry[0]; // "$username:$password"
$proxy_ip = $ip_arry[1];
try {
// $proxy = "107.170.255.191:10023"; // Proxy IP and port
// $proxy_username = "EZJi7";
// $proxy_password = "rL7wx";
$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)
// 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, CURLPROXY_SOCKS5); // For SOCKS5
// curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP); // For HTTP proxy
// Optional: Add timeout to handle unresponsive proxies
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
// Execute the cURL request
$response = curl_exec($ch);
// Check for errors
if (curl_errno($ch)) {
//echo "Proxy Error: " . curl_error($ch) . "\n";
return [0, curl_errno($ch)];
} else {
return [1, ""];
// echo "Proxy is working! Response: " . $response . "\n";
}
// Close the cURL session
curl_close($ch);
}catch(Exception $e) {
return [1, $e->getMessage() . " : Exception "];
}
}else{
try {
$ch = curl_init ();
curl_setopt ($ch, CURLOPT_URL, "http://www.cpanel.net/showip.cgi");
curl_setopt ($ch, CURLOPT_TIMEOUT, 15);
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 [1, $e->getMessage()];
}
}
}
إرسال تعليق