Advertisement
vidmantas

rekvizitu skriptas

Oct 25th, 2021
802
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.65 KB | None | 0 0
  1. <pre>
  2. <?php
  3.  
  4.  
  5. function &request($url, $referer=false)
  6. {
  7.     $ch = curl_init();
  8.  
  9.     curl_setopt($ch, CURLOPT_URL, $url);
  10.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  11.     curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
  12.  
  13.     curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');
  14.  
  15.     $headers = array();
  16.     $headers[] = 'Authority: rekvizitai.vz.lt';
  17.     $headers[] = 'Cache-Control: max-age=0';
  18.     $headers[] = 'Sec-Ch-Ua: \";Not A Brand\";v=\"99\", \"Chromium\";v=\"94\"';
  19.     $headers[] = 'Sec-Ch-Ua-Mobile: ?0';
  20.     $headers[] = 'Sec-Ch-Ua-Platform: \"Linux\"';
  21.     $headers[] = 'Upgrade-Insecure-Requests: 1';
  22.     $headers[] = 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.81 Safari/537.36';
  23.    
  24.     $headers[] = 'Sec-Fetch-Site: same-origin';
  25.     $headers[] = 'Sec-Fetch-Mode: navigate';
  26.     $headers[] = 'Sec-Fetch-User: ?1';
  27.     $headers[] = 'Sec-Fetch-Dest: document';
  28.     $headers[] = 'Referer: '.$referer;
  29.     $headers[] = 'Accept-Language: en-GB,en-US;q=0.9,en;q=0.8,lt-LT;q=0.7,lt;q=0.6,ru;q=0.5';
  30.     $headers[] = 'Cookie: _ga=GA1.2.1267708846.1633970398; PHPSESSID=jju8t73qe97iiiej2f1bapv6gr; _gid=GA1.2.702172919.1635163877';
  31.    
  32.     curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  33.  
  34.     //curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, true);  
  35.     //curl_setopt($ch, CURLOPT_PROXY, 'localhost:8118');
  36.    
  37.     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  38.     $html = curl_exec($ch);
  39.     if (curl_errno($ch)) {
  40.         echo 'Error:' . curl_error($ch);
  41.     }
  42.     curl_close($ch);
  43.  
  44.    
  45.     if(strpos($html, 'IsUnusualTrafficFormValid')!==false || strpos($html,'Oi..! Neskubėkite!')!==false){
  46.        
  47.         echo("captcha on ".$url);
  48.         $html = "";
  49.         return $html;
  50.     }  
  51.    
  52.     return $html;
  53. }
  54.  
  55. function cFileSize($bytes, $prec = 2)
  56. {
  57.     if (!$bytes)
  58.         return '0';
  59.     $m = array('', 'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y');
  60.     $exp = floor(log($bytes) / log(1024));
  61.     $prec = pow(10, $prec);
  62.     return (round($bytes / pow(1024, floor($exp)) * $prec) / $prec) . ' ' . $m[$exp] . 'B';
  63. }
  64.  
  65.  
  66. function parseParams()
  67. {
  68.     $params = array();
  69.     foreach ($GLOBALS['argv'] as $arg)
  70.         if (preg_match('/--(.*?)=(.*)/', $arg, $reg))
  71.             $params[$reg[1]] = $reg[2];
  72.         elseif (preg_match('/-([a-z0-9_-]*)/i', $arg, $reg))
  73.             $params[$reg[1]] = true;
  74.  
  75.     return $params;
  76. }
  77.  
  78. class walkcat
  79. {
  80.     function __construct() {
  81.         $imones = file_get_contents(__DIR__.'/repos/imones.dat');
  82.         $imones = json_decode($imones, true);
  83.        
  84.         $this->kategorijos = $imones;
  85.  
  86.  
  87.         $this->medis = json_decode(file_get_contents(__DIR__.'/repos/medis.dat'), true);
  88.        
  89.         $this->params = parseParams();
  90.     }
  91.  
  92.     function getCat($cat,$page=1){
  93.         $url="https://rekvizitai.vz.lt/imones/".$cat."/".$page;
  94.         $referer = $url="https://rekvizitai.vz.lt/imones/".$cat."/".($page == 1 ? '1': $page-1);
  95.         $html = request($url, $referer);
  96.  
  97.         echo "Fetch $cat page $page - $url | ".cFileSize(memory_get_usage())."\n";
  98.        
  99.        
  100.         file_put_contents(__DIR__.'/repos/lastcat.html', $html);
  101.        
  102.         sleep(2);
  103.        
  104.  
  105.  
  106.         return $html;
  107.     }
  108.  
  109.     function testAddr(){
  110.         echo "IP:".request('http://addr.gw.lt/')."\n";
  111.     }
  112.     function restartTor()
  113.     {
  114.         $this->testAddr();
  115.         echo "restarting tor\n";
  116.         shell_exec("sudo /usr/sbin/service tor restart");
  117.         sleep(10);
  118.         $this->testAddr();
  119.     }
  120.    
  121.     function processCat($cat, $startpage){
  122.        
  123.         $lastpage = 999;
  124.        
  125.         for($i=$startpage;$i<=$lastpage;$i++){
  126.            
  127.            
  128.            
  129.             $html = $this->getCat($cat, $i);
  130.            
  131.             if($lastpage==999){
  132.                 preg_match('/Paskutinis puslapis"\>(\d+)\</i', $html, $lastpage);
  133.                 $lastpage=$lastpage[1];
  134.                 echo "Last page: $lastpage\n";
  135.             }
  136.            
  137.             preg_match_all('/https:\/\/rekvizitai.vz.lt\/imone\/(.[a-z_0-9]+)\//i', $html, $matches);
  138.  
  139.             echo "found matches ".implode(',', $matches[1]) ."\n";
  140.            
  141.            
  142.             if(!count($matches[1])){
  143.                
  144.                 $this->save($cat, $i);
  145.                 $i--;
  146.                 $this->restartTor();
  147.                 sleep(10);
  148.             }
  149.            
  150.            
  151.             foreach($matches[1] as $kodas){
  152.                 $this->medis[$cat][$kodas]=1;
  153.             }
  154.            
  155.         }
  156.        
  157.         $this->save($cat, $i);
  158.     }
  159.    
  160.     function process(){
  161.        
  162.         $this->testAddr();
  163.        
  164.        
  165.         print_r($this->medis['fetch_info']['last_cat']);
  166.        
  167.        
  168.         foreach($this->kategorijos as $cat)
  169.         {
  170.             if(isset($this->medis[$cat]) && $this->medis['fetch_info']['last_cat']['cat']!=$cat)
  171.                 continue;
  172.            
  173.             $startpage = $this->medis['fetch_info']['last_cat']['cat']==$cat ? $this->medis['fetch_info']['last_cat']['page']-1 :1;
  174.            
  175.             $this->processCat($cat, $startpage);
  176.            
  177.         }
  178.     }
  179.    
  180.    
  181.     function save($cat=false,$lastpage=false)
  182.     {
  183.         $this->medis['fetch_info']['last_cat']=['cat'=>$cat,'page'=>$lastpage];
  184.        
  185.         file_put_contents(__DIR__.'/repos/medis.dat', json_encode($this->medis, JSON_PRETTY_PRINT));
  186.     }
  187.    
  188.    
  189.  
  190. }
  191.  
  192.  
  193. $o = new walkcat;
  194. $o->process();
  195. $o->save();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement