163爬

<?php
header("Content-Type:text/html;charset=utf-8");
date_default_timezone_set("PRC");
//时区
ignore_user_abort(); //关掉浏览器,PHP脚本也可以继续执行.
set_time_limit(0); // 通过set_time_limit(0)可以让程序无限制的执行下去


//得到数组(无限种组合)
$keywordData = keyword();
//遍历(没有注册的保存)
foreach ($keywordData as $value) {
   test163($value);
}



function keyword(){
    $data = ['a','b','c','d','e','f','g','h','i','j','k','m','n','o','p','q','r','s','t','u','v','w','x','y','z'];
    $password = [];
    //循环获取无数种组合
    $x = 0;
    while($x<500000){
        // 六位数字自由组合
        $password[] = $data[rand(0,count($data)-1)].$data[rand(0,count($data)-1)].$data[rand(0,count($data)-1)].$data[rand(0,count($data)-1)].$data[rand(0,count($data)-1)].$data[rand(0,count($data)-1)];
        $x++;
    }

    //去重
    $password = array_unique($password);    
    return $password;
}

//测试是否注册并写入
function test163($name){
    $url = 'https://zc.reg.163.com/checkName?id=0D01F7D851B271968D5B35E89202905BC6092133D3C37625473CF2F8EAF28FC7171B29A2CB5D39109AA79FD2213EB3BC0C2FB85B7B60CA6CB0491C37D20B20E4BBD7A26894CE8F0114FA96CC3AD21D06&channel=6&userName='.$name.'%40163.com&nocache=1535619264598&rtid=8xon005EAKVgrMOtSh0btbJNoiXdhOhr';

    //获取json数组
    $data = json_decode(_grab($url),true);

    if($data['ret']==104){
       $result = '-------------------------'.$name.'-------------------------';
         //写入日志
        my_log($result);        
    }
/*    else if($data['ret']==407){
       $result =  date('Y年m月d日 H:i',time()).':'.$name.':不能注册!';
    }else{
       $result = date('Y年m月d日 H:i',time()).':'.$name.':'.json_encode($data);
    }
 */
}

//写入日志date('m_d')
function my_log($data){
   $log_file = date('m___d',time()).'.txt';
  /* $content =var_export($data,TRUE);*/
   $data .= "\r\n";
   file_put_contents($log_file,$data, FILE_APPEND);
}


function _grab($curl,$postInfo='',$cookie='',$referer='',$userAgent=''){
     $ch = curl_init();  
     curl_setopt($ch, CURLOPT_URL, $curl);  
     //不输出头
     curl_setopt($ch, CURLOPT_HEADER, 0);   
     //以字符串返回获取的信息,不直接输出
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     //如果是https链接,不验证证书
     if(preg_match('/https/i', $curl)){
         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
     }
     //POST
     if($postInfo){
        curl_setopt($ch,CURLOPT_POST,1);
        curl_setopt($ch,CURLOPT_POSTFIELDS,$postInfo);
     }
     //加入cookie
     if($cookie){
         curl_setopt($ch,CURLOPT_COOKIE,$cookie);
     }
     //模拟来路
     if($referer){
         curl_setopt($ch, CURLOPT_REFERER, $referer);
     }
     //模拟环境
     if($userAgent){
         curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
     }
     //执行
     $content = curl_exec($ch);  
     //错误处理
     if ($content  === false) {  
       return "网络请求出错: " . curl_error($ch);  
       exit();  
     }  
     return $content;
}    

猜你喜欢

转载自www.cnblogs.com/cl94/p/9562536.html
163