cdw1p

Proxy Crawler + Auto Check + Auto Save Live

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