欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

php curl 自己亲自做的 立讯的 curl 的 dhcp 有大用 有大大用 有大大大用

function custom_eleven_get_repeat_dhcp_get_repeat_dhcp_data()
{
   // ini_set("log_errors", "on");
   // ini_set("error_log", "php_erroraaaaaaa.log");
   global $user;
   //    $rurl = $_GET['rurl'];
   //    if(empty($rurl)){
   //    }
   //    else{
   ////        var_dump($rurl);exit;
   //    }
   unlink(dirname(__FILE__) . '/all_data_' . $user->uid . '.txt');
   $rul_old = $rurl = 'http://jses.xxxx.com.cn/DHCPIPs';                                   //需要转到的b.domain.com中的页面
   //把它弄成最大1000页吧
   for ($i = 1; $i < 500; $i++) {
       $rurl = $rul_old . '?pageNumber=' . $i;
       $ch = curl_init();
       // $_COOKIE = array(
       //     'MyCookieName' => 'ra6Xvxlxxxxl5fqCJ7vyycq6DEb63m2kulWSAPMYMjVojzr-JMgCc5dWt0sBjwyD2FTkYW6X6uOw-Z4HANr-UBGeA2qpmotL_33T7SctltcFeokGznTtrXtb-YUHBxPZGvJUsvhMmj6bT4cr7wGfQNbtEiGlwFXjw_uuVtER-FbQ8CuZjMljEAwHuJ9-AQxP1cJBJ5B6lTh-SKAu0BOUWcLheE4NArxIJkvi53VZEwKMJE0G422KsZDzoAOodXpOyaaxI9oM2cZ0uaFpwdlfURGtzalEiiWSVes1HErLysWR_-Tsp8NMYY3wWjMrXqvzbtnXoSSSNK_37ozn3yVRXt0Wzpq9em-mjXlAyHQVYGzh21lxImmW0IuV-8tyH7pmw9xfAoxPeUwaXqSCSn30vu6mOqvF3Nw9KvOEjLb8LgIlji1-VsL3VGxUHGD6F99OBdOWYSLPcm0eBmkx2GLbwctcrZglB-z__yCgOCZqR2hy3YLmQzxo7N9wndUTHxUAyWE55GDkjnv7Tg9VAuZsfwASjfWTp2ZxdxJNPHfAuAVvRzjFhnr2w-XR7ZxbeWbYAfMBV-_ZMDViEHjTftWaf5aL_Thnt347jU_-Na7BEkObQckeXjOxrh4_nBjjmupc0q2O5uYHKUxGwEM179yKSNsmF6IIbkxE0H5lm790cHawNauX4T1XJaNJPRTOrMuqa-B5AKkENgxTVefHlXbrpXF976XcPvubwAdaqo8TVFsThXG_UB4aP7fkwWzHGSn7K8xLB-XMYikbTOqOl5u9Ww09kyJwp0SXHw0ckZ0Cp03bUnAVi_I0T5HV7v6nQT2dyLZ5rM4NH0P40hJkpEAm9GA2jwVEAPL0Wo32Z60ESyY3CCV0ehh_DhD6MGxcvr9dvj-xYBtZQV2D4uDG7Fao_vRqqO1gJJJJCrpqITNZBCY0LoCTsOIqQ48mAAd0s6mx4GZSTeDrvXCUS4nKLmMLQflK-yU5_LJJJmmJY3X_IcAqaZBoR4oXn5Qp9dyCBs-WMSXFZ631HnmFEBvqd0FoIbg8urlyctI0OzdHyH3rs7dXiMa1GK0XM0k8sa9o0zPUX5ns7LfVsm42sEaHa85Ry_RHzFlm7TjdFItPrEl3NQDqJ-3p6MZWUwV0ztBeP0yz87xsY9YIvcrKoUmjjKqMjK3jkgS0z3Hp1VuSnyi22CYja_-YAHS5qYv9E_Ov6lKIaE_Ronbk74yv2yE7UTQ3YScsrsQD2rjapB2FlWSixNR4-N-u01ZwLDngABxs7s8xn_OKII0rJsahdO3lD_Kmwu8qQUyiSf39ax8n80RoKdrOYGMcGZIomUVuk95FQSv9s_ghplzeaFQ3WnSpsE1Jt-vXGFTQCHPg1El6kGHMeglJIUx2om8O1-sT_klDk7Hwojmv6f8eeK0PAYXEsekg',
       //     '__RequestVerificationToken' => 'yfahxxxxzFw4kt5ke_LHrTMZypb0hjCjkqDdPCFSrNPnODRjAnU8__FCu2xBHXfKJ8bbNbaLlpx9YhfKLL5mRlvaTxRTAphWgxyG_UgZvg1'
       // );
       $_COOKIE = array(
           'MyCookieName' => $_SESSION['MyCookieName'],
           '__RequestVerificationToken' => $_SESSION['__RequestVerificationToken'],
       );
       $cookie = ''; //处理COOKIE
       foreach ($_COOKIE as $key => $value) {
           $cookie .= "$key=$value; ";
       }
       $options = array(
           CURLOPT_URL => $rurl,
           CURLOPT_COOKIE => $cookie,
           CURLOPT_RETURNTRANSFER => true
       );
       curl_setopt_array($ch, $options);
       $ret = curl_exec($ch); // 抓取URL并把它传递给浏览器

       preg_match_all("/<table.*?>.*?<\/table>/ism", $ret, $out, PREG_SET_ORDER);
       curl_close($ch);
       $output = $out[0][0] . 'pageNumber=' . $i;
       if (!stripos($output, 'Edit')) {
           break;
       }
       file_put_contents(dirname(__FILE__) . '/all_data_' . $user->uid . '.txt', $output, FILE_APPEND);
   }


   $result_arr =  array();
   $str = file_get_contents(dirname(__FILE__) . '/all_data_' . $user->uid . '.txt');
   preg_match_all('/<tr>(.*?)<\/tr>/ism', $str, $tr_out, PREG_PATTERN_ORDER);

   foreach ($tr_out[0] as $key => $value) {
       preg_match_all('/<td>(.*?)<\/td>/ism', $value, $td_out, PREG_PATTERN_ORDER);
       $td_arr = $td_out[1];
       if (!empty($td_arr) && count($td_arr) > 0) {
           $temp_arr = array(
               'DHCPServer' => trim($td_arr[0]),
               'DeviceName' => trim($td_arr[1]),
               'IP' => trim($td_arr[2]),
               'MAC' => trim($td_arr[3]),
               'Mask' => trim($td_arr[4]),
               'Area' => trim($td_arr[5]),
               'NetLevel' => trim($td_arr[6]),
               'EmployeeID' => trim($td_arr[7]),
               'LeaseExpires' => trim($td_arr[8]),
               'edit_delete' => trim(str_replace('href="','target="_blank" href="http://rrrr.bbbb.com.cn',$td_arr[9])),
           );
           $result_arr[] = $temp_arr;
       }
   }

   $mac = array();
   foreach ($result_arr as $key => $value) {
       $mac[$key] = $value['MAC'];
   }
   $temp_arr = array_count_values($mac);
   $mac_num_arr = array();
   foreach($mac as $key=>$value)
   {
       $mac_num_arr[$key] = $temp_arr[$value];
   }
   // var_dump(array_count_values($mac));
   // var_dump($result_arr);
   array_multisort($mac_num_arr, SORT_DESC, SORT_NUMERIC,$mac,SORT_DESC, SORT_STRING,$result_arr);
   // var_dump($result_arr);

   $result_str =  '<table>';
   foreach($result_arr as $key=>$value)
   {
       $result_str .="<tr>";
       $result_str .="<td>".$value['DHCPServer']."</td>";
       $result_str .="<td>".$value['DeviceName']."</td>";
       $result_str .="<td>".$value['IP']."</td>";
       $result_str .="<td>".$value['MAC']."</td>";
       $result_str .="<td>".$value['Mask']."</td>";
       $result_str .="<td>".$value['Area']."</td>";
       $result_str .="<td>".$value['NetLevel']."</td>";
       $result_str .="<td>".$value['EmployeeID']."</td>";
       $result_str .="<td>".$value['LeaseExpires']."</td>";
       $result_str .="<td>".$value['edit_delete']."</td>";
       $result_str .="<td>".$mac_num_arr[$key]."次</td>";
       $result_str .="</tr>";

   }

   $result_str .=  '</table>';

   return $result_str;

   exit;
   
}


普通分类: