VanGans

Proxy Crawler + Auto Check + Auto Save Live Proxy

Apr 19th, 2019
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.26 KB | None | 0 0
  1. <?php
  2. /*
  3.  * Coded By VanGans
  4.  *
  5.  * Proxy Crawler + Auto Check + Auto Save Live Proxy
  6.  */
  7.  
  8. class Proxy {
  9.     private $response;
  10.     private $proxy;
  11.    
  12.     function ambilProxy() {
  13.         echo '#> Mengambil proxy...' . PHP_EOL;
  14.         $ch = curl_init();
  15.         curl_setopt($ch, CURLOPT_URL, 'https://free-proxy-list.net/');
  16.         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  17.         $resp = curl_exec($ch);
  18.         curl_close($ch);
  19.         $this->response = $resp;
  20.         return $this;
  21.     }
  22.    
  23.     function satukan() {
  24.         preg_match_all('/<tr><td>([0-9.]+)<\/td><td>([0-9]+)<\/td>/', $this->response, $result);
  25.         $this->proxy = array_combine($result[1], $result[2]);
  26.         return $this;
  27.     }
  28.    
  29.     function checkProxy($timeout = 10) {
  30.         $i = 0;
  31.         foreach($this->proxy as $ip => $port) {
  32.             echo "\e[44m#> Memeriksa proxy: ".$ip.':'.$port."\e[49m (".$i." of ".count($this->proxy).") | \e[4mCreated by rafinetiz\e[0m\r";
  33.             if($con = @fsockopen($ip, $port, $errno, $error, 10)) {
  34.                 echo "\033[K#> \e[32mLive\e[0m => ". $ip .':'. $port . PHP_EOL;
  35.                 file_put_contents('proxy.txt', $ip.':'.$port.PHP_EOL, FILE_APPEND);
  36.             } else {
  37.                 echo "\033[K#> \e[31mDie\e[0m  => ". $ip .':'. $port . ' | ' . $error . PHP_EOL;
  38.             }
  39.             $i++;
  40.         }
  41.     }
  42. }
  43.  
  44. $crawler = new Proxy();
  45. $crawler->ambilProxy()->satukan()->checkProxy();
Add Comment
Please, Sign In to add comment