Вход Регистрация
* Pelmeshka

прокси-чекер

  1. <?php
  2.  
  3. // Ensure that the timeouts from fsockopen don't get reported as errors (possible, depends on the php server config)
  4. // Limit the amount of proxies that can be tested at any one time
  5. $maximum_proxies_to_test = 50;
  6. // Enter a password (if required) to protect the page
  7. $password = '';
  8.  
  9. // Actual proxyjudge part of the page
  10. function return_env_variables()
  11. {
  12. echo '<pre>'."\n";
  13. foreach ($_SERVER as $header => $value )
  14. {
  15. if ((strpos($header , 'REMOTE')!== false || strpos($header , 'HTTP')!== false || strpos($header , 'REQUEST')!== false) && ( strpos($header , 'HTTP_HOST') !== 0))
  16. {
  17. echo $header.' = '.$value."\n";
  18. }
  19. }
  20. echo '</pre>';
  21. }
  22.  
  23. // Function to go away and get the page (calls through the proxy back to itself)
  24. function get_judge_page($proxy)
  25. {
  26. // Depending on the server environment, this timeout setting may not be available.
  27. $timeout = 15;
  28. $proxy_cont = '';
  29. list($proxy_host, $proxy_port) = explode(":", $proxy);
  30. $proxy_fp = fsockopen($proxy_host, $proxy_port, $errornumber, $errorstring, $timeout);
  31. if ($proxy_fp)
  32. {
  33. stream_set_timeout($proxy_fp, $timeout);
  34. fputs($proxy_fp, "GET " . $_SERVER['SCRIPT_NAME'] . "?test HTTP/1.0\r\nHost: " . $_SERVER['SERVER_NAME'] . "\r\n\r\n");
  35. while(!feof($proxy_fp))
  36. {
  37. $proxy_cont .= fread($proxy_fp,4096);
  38. }
  39. fclose($proxy_fp);
  40. $proxy_cont = substr($proxy_cont, strpos($proxy_cont,"\r\n\r\n")+4);
  41. }
  42. return $proxy_cont;
  43. }
  44.  
  45. // Check for the control string to see if it's a valid fetch of the judge
  46. function check_valid_judge_response($page)
  47. {
  48. if(strlen($page) < 5)
  49. return false;
  50. return strpos($page, 'REMOTE_ADDR') !== false;
  51. }
  52.  
  53. // Check for the IP addresses
  54. function check_anonymity($page)
  55. {
  56. if(strpos($page, $_SERVER['LOCAL_ADDR']) !== false)
  57. return false;
  58. return true;
  59. }
  60.  
  61. // Takes and tests a proxy
  62. // 0 - Bad proxy
  63. // 1 - Good (non anon) proxy
  64. // 2 - Good (anonymous) proxy
  65. function test_proxy($proxy)
  66. {
  67. $page = get_judge_page($proxy);
  68. if(!check_valid_judge_response($page))
  69. return 0;
  70. if(!check_anonymity($page))
  71. return 1;
  72. return 2;
  73. }
  74.  
  75. ////////// Main Page ////////////
  76.  
  77. // If this is a judge request, just return the environmental variables
  78. if(getenv('QUERY_STRING') == "test")
  79. {
  80. return_env_variables();
  81. }
  82. // Else check whether we have been passed a list of proxies to test or not
  83. // Should really use $_POST but it's been left as $HTTP_POST_VARS for older versions of php (3.x)
  84. elseif( (isset($HTTP_POST_VARS['action']) && $HTTP_POST_VARS['action'] === 'fred') &&
  85. (isset($HTTP_POST_VARS['proxies']) && $HTTP_POST_VARS['proxies'] != '') &&
  86. ( (strlen($password) == 0) || (isset($HTTP_POST_VARS['password']) && $HTTP_POST_VARS['password'] === $password) ))
  87. {
  88. $proxies = explode("\n", str_replace("\r", "", $HTTP_POST_VARS['proxies']), $maximum_proxies_to_test + 1);
  89.  
  90. // Set the overall time limit for the page execution to 10 mins
  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. switch(test_proxy($proxies[$thisproxy]))
  103. {
  104. case 2:
  105. echo ' - <font color="green">Анонимная</font><br>' . "\n";
  106. $anon_proxies[count($anon_proxies)] = $proxies[$thisproxy];
  107. break;
  108. case 1:
  109. echo ' - <font color="yellow">Не анонимная</font><br>' . "\n";
  110. $nonanon_proxies[count($nonanon_proxies)] = $proxies[$thisproxy];
  111. break;
  112. case 0:
  113. echo ' - <font color="red">Не рабочая</font><br>' . "\n";
  114. $bad_proxies[count($bad_proxies)] = $proxies[$thisproxy];
  115. break;
  116. }
  117. }
  118.  
  119. echo '<pre>';
  120. echo '<br><b><font color="green" size="2">Анонимные прокси:</font></b>' . "\n";
  121. for($thisproxy = 0; $thisproxy < count($anon_proxies); $thisproxy += 1)
  122. echo $anon_proxies[$thisproxy] . "\n";
  123. echo '<br><b><font color="yellow" size="2">Не анонимные прокси:</font></b>' . "\n";
  124. for($thisproxy = 0; $thisproxy < count($nonanon_proxies); $thisproxy += 1)
  125. echo $nonanon_proxies[$thisproxy] . "\n";
  126. echo '<br><b><font color="red" size="2">Не рабочие прокси:</font></b>' . "\n";
  127. for($thisproxy = 0; $thisproxy < count($bad_proxies); $thisproxy += 1)
  128. $xek = htmlspecialchars($bad_proxies[$thisproxy]);
  129. echo $xek . "\n";
  130. echo '</pre>';
  131. }
  132. // Just a blank call of the page - show the form for the user to fill in
  133. else
  134. {
  135.  
  136. echo '<form method="POST" action="' . $_SERVER['SCRIPT_NAME'] . '">' . "\n";
  137. echo '<input type="hidden" name="action" value="fred">' . "\n";
  138. echo '<textarea name="proxies" cols=50 rows=10></textarea><br>' . "\n";
  139. if(strlen($password) > 0)
  140. echo 'Password: <input type="password" name="password" size="15"><br>' . "\n";
  141. echo '<input type="submit" value="Старт">' . "\n";
  142. echo '</form>' . "\n";
  143. }
  144. ?>
» Описание: прокси-чекер
» Время добавления: 7 Ноября 2014 в 18:15
» Посмотров: 1926
» textarea
» Рейтинг: [+0 | -0]
Комментарии [0]
Онлайн: 1
Реклама