Advertisement
Guest User

Proxy Checker

a guest
Oct 18th, 2011
1,113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.72 KB | None | 0 0
  1. <?php  
  2.  
  3. // debug
  4.    error_reporting(0);  
  5. // you know  
  6.    $maximum_proxies_to_test = 50;  
  7. // password for page
  8.    $password = '';  
  9.  
  10. // let's roll
  11.    function return_env_variables()  
  12.    {  
  13.       echo '<pre>'."\n";  
  14.       foreach ($_SERVER as $header => $value )  
  15.       {  
  16.         if ((strpos($header , 'REMOTE')!== false || strpos($header , 'HTTP')!== false || strpos($header , 'REQUEST')!== false) && ( strpos($header , 'HTTP_HOST') !== 0))  
  17.         {  
  18.         echo $header.' = '.$value."\n";  
  19.         }  
  20.       }  
  21.       echo '</pre>';  
  22.    }  
  23.  
  24. // function to go away and get the page (calls through the proxy back to itself)  
  25.    function get_judge_page($proxy)  
  26.    {  
  27.    // Depending on the server environment, this timeout setting may not be available.      
  28.       $timeout = 15;  
  29.       $proxy_cont = '';  
  30.       list($proxy_host, $proxy_port) = explode(":", $proxy);  
  31.       $proxy_fp = fsockopen($proxy_host, $proxy_port, $errornumber, $errorstring, $timeout);  
  32.       if ($proxy_fp)  
  33.       {  
  34.          stream_set_timeout($proxy_fp, $timeout);  
  35.          fputs($proxy_fp, "GET " . $_SERVER['SCRIPT_NAME'] . "?test HTTP/1.0\r\nHost: " . $_SERVER['SERVER_NAME'] . "\r\n\r\n");  
  36.          while(!feof($proxy_fp))  
  37.          {  
  38.                $proxy_cont .= fread($proxy_fp,4096);  
  39.          }  
  40.          fclose($proxy_fp);  
  41.          $proxy_cont = substr($proxy_cont, strpos($proxy_cont,"\r\n\r\n")+4);  
  42.       }  
  43.       return $proxy_cont;    
  44.    }  
  45.  
  46. // check for the control string to see if it's a valid fetch of the judge  
  47.    function check_valid_judge_response($page)  
  48.    {  
  49.       if(strlen($page) < 5)  
  50.          return false;  
  51.       return strpos($page, 'REMOTE_ADDR') !== false;  
  52.    }  
  53.  
  54. // check for the IP addresses :3
  55.    function check_anonymity($page)  
  56.    {  
  57.       if(strpos($page, $_SERVER['LOCAL_ADDR']) !== false)  
  58.          return false;  
  59.       return true;  
  60.    }  
  61.  
  62. // takes and tests a proxy  
  63. // 0 - bad proxy  
  64. // 1 - good (non anonymous) proxy  
  65. // 2 - good (anonymous) proxy  
  66.    function test_proxy($proxy)  
  67.    {  
  68.       $page = get_judge_page($proxy);  
  69.       if(!check_valid_judge_response($page))  
  70.          return 0;  
  71.       if(!check_anonymity($page))  
  72.          return 1;  
  73.       return 2;  
  74.    }  
  75.  
  76. // if this is a judge request, just return the environmental variables  
  77.    if(getenv('QUERY_STRING') == "test")  
  78.    {  
  79.       return_env_variables();  
  80.    }  
  81. // else check whether we have been passed a list of proxies to test or not  
  82. // should really use $_POST but it's been left as $HTTP_POST_VARS for older versions of PHP
  83.    elseif( (isset($HTTP_POST_VARS['action']) && $HTTP_POST_VARS['action'] === 'fred') &&  
  84.            (isset($HTTP_POST_VARS['proxies']) && $HTTP_POST_VARS['proxies'] != '') &&  
  85.            ( (strlen($password) == 0) || (isset($HTTP_POST_VARS['password']) && $HTTP_POST_VARS['password'] === $password) ))  
  86.    {  
  87.       $proxies = explode("\n", str_replace("\r", "", $HTTP_POST_VARS['proxies']), $maximum_proxies_to_test + 1);  
  88.        
  89.    // set the overall time limit for the page execution to 10 mins  
  90.       set_time_limit(600);  
  91.        
  92.    // set up some arrays to hold the results  
  93.       $anon_proxies = array();  
  94.       $nonanon_proxies = array();  
  95.       $bad_proxies = array();  
  96.      
  97.    // loop through and test the proxies  
  98.       for($thisproxy = 0; $thisproxy < ($maximum_proxies_to_test > count($proxies) ? count($proxies) : $maximum_proxies_to_test); $thisproxy += 1)  
  99.       {  
  100.            $draculalol = htmlspecialchars($proxies[$thisproxy]);
  101.          echo '' . $draculalol . '';  
  102.          flush();  
  103.          switch(test_proxy($proxies[$thisproxy]))  
  104.          {  
  105.             case 2:  
  106.               echo ' - <font color="green">Анонимная</font><br>' . "\n";  
  107.                $anon_proxies[count($anon_proxies)] = $proxies[$thisproxy];  
  108.                break;  
  109.             case 1:  
  110.               echo ' - <font color="yellow">Не анонимная</font><br>' . "\n";  
  111.                $nonanon_proxies[count($nonanon_proxies)] = $proxies[$thisproxy];  
  112.                break;  
  113.             case 0:  
  114.               echo ' - <font color="red">Не рабочая</font><br>' . "\n";  
  115.                $bad_proxies[count($bad_proxies)] = $proxies[$thisproxy];  
  116.                break;  
  117.          }  
  118.       }  
  119.      
  120.       echo '<pre>';  
  121.       echo '<br><b><font color="green" size="2">Анонимные прокси:</font></b>' . "\n";  
  122.       for($thisproxy = 0; $thisproxy < count($anon_proxies); $thisproxy += 1)  
  123.          echo $anon_proxies[$thisproxy] . "\n";  
  124.       echo '<br><b><font color="yellow" size="2">Не анонимные прокси:</font></b>' . "\n";  
  125.       for($thisproxy = 0; $thisproxy < count($nonanon_proxies); $thisproxy += 1)  
  126.          echo $nonanon_proxies[$thisproxy] . "\n";  
  127.       echo '<br><b><font color="red" size="2">Не рабочие прокси:</font></b>' . "\n";  
  128.       for($thisproxy = 0; $thisproxy < count($bad_proxies); $thisproxy += 1)  
  129.             $xek = htmlspecialchars($bad_proxies[$thisproxy]);
  130.          echo $xek . "\n";  
  131.       echo '</pre>';  
  132.    }  
  133. // just a blank call of the page - show the form for the user to fill in  
  134.    else  
  135.    {  
  136.      
  137.       echo '<form method="POST" action="' . $_SERVER['SCRIPT_NAME'] . '">' . "\n";  
  138.       echo '<input type="hidden" name="action" value="fred">' . "\n";  
  139.       echo '<textarea name="proxies" cols=50 rows=10></textarea><br>' . "\n";
  140.       if(strlen($password) > 0)    
  141.          echo 'Password: <input type="password" name="password" size="15"><br>' . "\n";  
  142.       echo '<input type="submit" value="Старт">' . "\n";  
  143.       echo '</form>' . "\n";  
  144.    }  
  145. ?>
  146.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement