field('Id,Token')->fetchAll(); // //测试用 // $xingxing_data = get_product(__DIR__ . '/data/xingxing.csv'); // $xingxing_f = fopen(__DIR__ . '/data/xingxing.csv', 'w'); // $time = time(); // $noce = md5(time()); // $apikey = 'd50f2b2ffd421efa67df8efb96d5ff6c'; // $sign = md5($time.$noce.$apikey); // $url = "http://106.54.198.154/api/getNodeList?agentid=admin1&ti=".$time."&nonce=".$noce."&sign=".$sign; // $xingxing = json_decode(file_get_contents($url), true)['data']; // //写入星星文件 // xingxing_getList($xingxing, $xingxing_f, $all, $xingxing_data); // fclose($xingxing_f); // die; $all = fopen(__DIR__ . '/data/all.csv', 'w'); $dnx_exit = fopen(__DIR__ . '/data/dns_diff.csv', 'a'); $dnx_has_exit = get_product(__DIR__ . '/data/dns_diff.csv', 1); $qiangzi = json_decode(file_get_contents("http://47.92.116.14:2222/api/areaPool.html?type=json"), true); if(!empty($qiangzi)){ $qiangzi_data = get_product(__DIR__ . '/data/qiangzi.csv'); $qiangzi_f = fopen(__DIR__ . '/data/qiangzi.csv', 'w'); //写入强子文件 qiangzi_getList($qiangzi, $qiangzi_f, $all, $qiangzi_data); fclose($qiangzi_f); } $xingxing_data = get_product(__DIR__ . '/data/xingxing.csv'); $xingxing_f = fopen(__DIR__ . '/data/xingxing.csv', 'w'); $time = time(); $noce = md5(time()); $apikey = 'd50f2b2ffd421efa67df8efb96d5ff6c'; $sign = md5($time.$noce.$apikey); $url = "http://106.54.198.154/api/getNodeList?agentid=admin1&ti=".$time."&nonce=".$noce."&sign=".$sign; $xingxing = json_decode(file_get_contents($url), true)['data']; //写入星星文件 xingxing_getList($xingxing, $xingxing_f, $all, $xingxing_data); fclose($xingxing_f); $jike_data = get_product(__DIR__ . '/data/jike.csv'); $jike_f = fopen(__DIR__ . '/data/jike.csv', 'w'); $jike = json_decode(file_get_contents("http://api.webok.me/beikeiplist/"), true)['data']; //写入极客文件 jike_getList($jike, $jike_f, $all, $jike_data); fclose($jike_f); $xigua_data = get_product(__DIR__ . '/data/xigua.csv'); $xigua_f = fopen(__DIR__ . '/data/xigua.csv', 'w'); $xigua = json_decode(file_get_contents("http://api.webok.me/serverlistyzip/"), true)['data']; //写入西瓜文件 jike_getList($xigua, $xigua_f, $all, $xigua_data, false); fclose($xigua_f); $tiantian_data = get_product(__DIR__ . '/data/tiantian.csv'); $tiantian_f = fopen(__DIR__ . '/data/tiantian.csv', 'w'); $tiantian = json_decode(file_get_contents("http://api.ipzuiduo.com/api/areas?apiid=135&sendtime=" . time() . "&sign=" . md5('apiid=135&sendtime=' . time() . '7dayCFfY6zcwJa6QHtHbGQBRckjJbrbS')), true)['data']; //写入天天文件 tiantian_getList($tiantian, $tiantian_f, $all, $tiantian_data, '天天'); fclose($tiantian_f); $mogu_data = get_product(__DIR__ . '/data/mogu.csv'); $mogu_f = fopen(__DIR__ . '/data/mogu.csv', 'w'); // echo 123; $mogu = json_decode(get_content("http://xjip.hlapi.com/api/area",''), true)['data']; // print_r($mogu); //写入蘑菇文件 mogu_getList($mogu, $mogu_f, $all, $mogu_data, '蘑菇'); fclose($mogu_f); $laoying_data = get_product(__DIR__ . '/data/laoying.csv'); $laoying_f = fopen(__DIR__ . '/data/laoying.csv', 'w'); $laoying = json_decode(get_content('https://dl.ipduoduo.com/api/area?_=1604541004026', $product_list[4]['Token']), true)['data']; //写入老鹰文件 tiantian_getList($laoying, $laoying_f, $all, $laoying_data, '老鹰'); fclose($laoying_f); $shihui_data = get_product(__DIR__ . '/data/shihui.csv'); $shihui_f = fopen(__DIR__ . '/data/shihui.csv', 'w'); $shihui = get_content('http://39.96.182.192:8888/agent.html', $product_list[15]['Token']); //写入实惠文件 shihui_getList($shihui, $shihui_f, $all, $shihui_data); fclose($shihui_f); $gongxiang_data = get_product(__DIR__ . '/data/gongxiang.csv'); $gongxiang_f = fopen(__DIR__ . '/data/gongxiang.csv', 'w'); $gongxiang = get_content('http://221.225.83.92:39999/agent/serversList.html', $product_list[14]['Token']); gongxiang_getList($gongxiang, $gongxiang_f, $all, $gongxiang_data); fclose($gongxiang_f); $xunlian = json_decode(file_get_contents("http://xunyou.ippptp.com:2222/api/areaPool.html?type=json"), true); if ($xunlian){ $xunlian_data = get_product(__DIR__ . '/data/xunlian.csv'); $xunlian_f = fopen(__DIR__ . '/data/xunlian.csv', 'w'); //写入讯连文件 xunlian_getList($xunlian, $xunlian_f, $all, $xunlian_data); fclose($xunlian_f); } // $wuxian_data = get_product(__DIR__ . '/data/wuxian.csv'); // $wuxian_f = fopen(__DIR__ . '/data/wuxian.csv', 'w'); // $wuxian = get_content('http://221.225.83.92:6888/agent/serversList.html', $product_list[9]['Token']); // //写入无限文件 // gongxiang_getList($wuxian, $wuxian_f, $all, $wuxian_data, '无限'); // fclose($wuxian_f); $xianfeng_data = get_product(__DIR__ . '/data/xianfeng.csv'); $xianfeng_f = fopen(__DIR__ . '/data/xianfeng.csv', 'w'); $xianfeng = json_decode(file_get_contents("http://apiserver.pptp.biz/Apiserver/getserver"), true); //写入先锋文件 xianfeng_getList($xianfeng, $xianfeng_f, $all, $xianfeng_data); fclose($xianfeng_f); $jinrui_data = get_product(__DIR__ . '/data/jinrui.csv'); $jinrui_f = fopen(__DIR__ . '/data/jinrui.csv', 'w'); $jinrui = file_get_contents("http://pptp.zhekou5.com/api/getnas.php"); //写入金瑞文件 jinrui_getList($jinrui, $jinrui_f, $all, $jinrui_data); fclose($jinrui_f); //星星2288写入all $file2288 = fopen(__DIR__ . '/data/2288.csv', 'r'); while ($data = fgetcsv($file2288)) { fputcsv($all, $data); } fclose($file2288); fclose($all); fclose($dnx_exit); sleep(5); auto_format_list(); //强子服务器解析规则 function qiangzi_getList($data, &$file, &$all, $exit) { global $dnx_exit, $dnx_has_exit; $online = ['故障', '正常', '异常']; $status = ['正常', '拥挤', '超载']; $key = ''; $list1 = []; foreach ($data as $info) { $record = []; $record['name'] = '强子'; //如果存在 不为空 则 if (!empty($info['titleRow'])) { $record['city'] = $info['titleRow']; $key = $record['city']; $list1[$key][] = $record; } if (empty($info['province'])) { $record['city'] = $info['description']; } else { $record['city'] = trim($info['city'], '\"'); } if (strpos($info['description'], '省混')) { $record['city'] = $info['description']; } $record['city'] = str_replace(' ', '', $record['city']); if (strpos($info['description'], '电信') !== false) { $record['supply'] = '电信'; } elseif (strpos($info['description'], '联通') !== false) { $record['supply'] = '联通'; } elseif (strpos($info['description'], '移动') !== false) { $record['supply'] = '移动'; } else { $record['supply'] = '电信/联通'; } $daikuan = explode('带宽', trim($info['description2'])); $record['ip'] = $daikuan[0]; $record['daikuan'] = $daikuan[1]; $record['onlineuser'] = $info['onlineuser']; $record['maxuser'] = $info['maxuser']; $record['online'] = $info['online'] == 1 ? '正常' : '故障'; $record['status'] = $status[$info['status']]; if (strpos($info['description'], '省混')) { $record['nasname'] = $info['nasname']; if (!in_array($record['nasname'], $exit) && !in_array($record['nasname'], $dnx_has_exit)) { fputcsv($dnx_exit, ['强子', $record['nasname'], date('Y-m-d H:i:s')]); } $list1[$key][] = $record; } else { for ($i = 1; $i < 6; $i++) { if (!empty($info['nasname' . $i])) { $record['nasname'] = $info['nasname' . $i]; if (!in_array($record['nasname'], $exit) && !in_array($record['nasname'], $dnx_has_exit)) { fputcsv($dnx_exit, ['强子', $record['nasname'], date('Y-m-d H:i:s')]); } $list1[$key][] = $record; } } } } foreach ($list1 as $val) { foreach ($val as $net_data) { fputcsv($file, $net_data); fputcsv($all, $net_data); } } } //星星服务器解析 function xingxing_getList($data, &$file, &$all, $exit) { global $dnx_exit, $dnx_has_exit; $online = ['故障', '正常', '正常']; $province_record = []; $key = ''; $list1 = []; //省会 $province = ['黑龙', '内蒙']; $citys = ['北京', '上海', '天津', '重庆']; foreach ($data as $info) { $record = []; $record['name'] = '星星'; $province_detail = mb_substr($info['name'], 0, 2); if (in_array($province_detail, $province)) { $province_detail = mb_substr($info['name'], 0, 3); $info['name'] = mb_substr($info['name'], 3); } elseif (!in_array($province_detail, $citys)) { $info['name'] = mb_substr($info['name'], 2); } if (!in_array($province_detail, $province_record)) { $record['city'] = $province_detail; $province_record[] = $province_detail; $key = $province_detail; $list1[$key][] = $record; } $city_ex = explode('电信', $info['name']); if (strpos($info['name'], '电信') !== false) { $record['city'] = $city_ex[0] . ($city_ex[1] ?? ''); $record['supply'] = '电信'; } elseif (strpos($info['name'], '联通') !== false) { $record['city'] = $city_ex[0] . ($city_ex[1] ?? ''); $record['supply'] = '联通'; } elseif (strpos($info['name'], '移动') !== false) { $record['city'] = $city_ex[0] . ($city_ex[1] ?? ''); $record['supply'] = '移动'; } else { $record['city'] = $info['name']; $record['supply'] = '电信/联通'; } $record['ip'] = strpos($info['name2'], '-') ? explode('-', $info['name2'])[1] : $info['name2']; $record['daikuan'] = strpos($info['name2'], '-')[1]; $record['onlineuser'] = ''; $record['maxuser'] = ''; $record['online'] = ($info['status'] == 1) ? '正常' : '故障'; $record['status'] = ''; $record['nasname'] = $info['host']; if (!in_array($record['nasname'], $exit) && !in_array($record['nasname'], $dnx_has_exit)) { fputcsv($dnx_exit, ['星星', $record['nasname'], date('Y-m-d H:i:s')]); } $key = $province_detail; $list1[$key][] = $record; } foreach ($list1 as $val) { foreach ($val as $net_data) { fputcsv($file, $net_data); fputcsv($all, $net_data); } } } //极客服务器解析 function jike_getList($data, &$file, &$all, $exit, $is_jike = true) { global $dnx_exit, $dnx_has_exit; $status = ['yes' => '正常', 'no' => '故障']; $key = ''; $list1 = []; $province_record = []; foreach ($data as $info) { $record = []; if($is_jike){ $record['name'] = '极客'; } else { $record['name'] = '西瓜'; } //如果存在 不为空 则 if (!in_array($info['province'], $province_record)) { $record['city'] = $info['province']; $province_record[] = $info['province']; $key = $record['city']; $list1[$key][] = $record; } if (empty($info['city'])) { $record['city'] = '全国混播'; } else { $record['city'] = $info['city']; } $record['supply'] = $info['isp']; $record['ip'] = ''; $record['daikuan'] = ''; $record['onlineuser'] = ''; $record['maxuser'] = ''; $record['online'] = $status[$info['status']]; $record['status'] = ''; $record['nasname'] = $info['domain']; if (!in_array($record['nasname'], $exit) && !in_array($record['nasname'], $dnx_has_exit)) { fputcsv($dnx_exit, [$record['name'], $record['nasname'], date('Y-m-d H:i:s')]); } $list1[$key][] = $record; } foreach ($list1 as $val) { foreach ($val as $net_data) { fputcsv($file, $net_data); fputcsv($all, $net_data); } } } //天天服务器解析规则 function tiantian_getList($data, &$file, &$all, $exit, $product_name) { global $dnx_exit, $dnx_has_exit; $status = ['故障', '正常']; $key = ''; $list1 = []; foreach ($data as $info) { $record = []; $record['name'] = $product_name; $record['city'] = $info['name']; $key = $record['city']; $list1[$key][] = $record; foreach ($info['areas'] as $v) { if (strpos($v['name'], '电信') !== false) { $record['city'] = explode('电信', $v['name'])[0]; $record['supply'] = '电信'; } elseif (strpos($v['name'], '联通') !== false) { $record['city'] = explode('联通', $v['name'])[0]; $record['supply'] = '联通'; } elseif (strpos($v['name'], '移动') !== false) { $record['city'] = explode('移动', $v['name'])[0]; $record['supply'] = '移动'; } else { $record['city'] = $v['name']; $record['supply'] = '电信/联通'; } $record['ip'] = ''; $record['daikuan'] = ''; $record['onlineuser'] = ''; $record['maxuser'] = ''; $record['online'] = empty($v['status']) ? '故障' : $status[$v['status']]; $record['status'] = ''; $record['nasname'] = $v['address']; if (!in_array($record['nasname'], $exit) && !in_array($record['nasname'], $dnx_has_exit)) { fputcsv($dnx_exit, [$product_name, $record['nasname'], date('Y-m-d H:i:s')]); } $list1[$key][] = $record; } } foreach ($list1 as $val) { foreach ($val as $net_data) { fputcsv($file, $net_data); fputcsv($all, $net_data); } } } //蘑菇服务器解析规则 function mogu_getList($data, &$file, &$all, $exit, $product_name) { global $dnx_exit, $dnx_has_exit; $status = ['故障', '正常']; $key = ''; $list1 = []; // print_r($data); foreach ($data as $info) { $record = []; $record['name'] = $product_name; $record['city'] = $info['title']; $key = $record['city']; $list1[$key][] = $record; foreach ($info['children'] as $v) { if (strpos($v['title'], '电信') !== false) { $record['city'] = explode('电信', $v['title'])[0]; $record['supply'] = '电信'; } elseif (strpos($v['title'], '联通') !== false) { $record['city'] = explode('联通', $v['title'])[0]; $record['supply'] = '联通'; } elseif (strpos($v['title'], '移动') !== false) { $record['city'] = explode('移动', $v['title'])[0]; $record['supply'] = '移动'; } else { $record['city'] = $v['title']; $record['supply'] = '电信/联通'; } $record['ip'] = ''; $record['daikuan'] = $v['bandwidth']; $record['onlineuser'] = ''; $record['maxuser'] = ''; $record['online'] = $v['status'] ? '正常' : '故障'; $record['status'] = ''; $record['nasname'] = $v['address'][0]; if (!in_array($record['nasname'], $exit) && !in_array($record['nasname'], $dnx_has_exit)) { fputcsv($dnx_exit, [$product_name, $record['nasname'], date('Y-m-d H:i:s')]); } $list1[$key][] = $record; } } foreach ($list1 as $val) { foreach ($val as $net_data) { fputcsv($file, $net_data); fputcsv($all, $net_data); } } } function shihui_getList($html, &$file, &$all, $exit) { // global $dnx_exit, $dnx_has_exit; // $key = ''; // $list1 = []; // preg_match("/

(.*\s*?)

 <\/p><\/div>/is", $html, $result); // preg_match_all("/

(.*?)<\/p>/is", $result[0], $result); // foreach ($result[0] as $k => $info) { // $record = []; // $record['name'] = '实惠'; // if ($k == 0 || $k == 5) { // continue; // } else { // $list = explode('
', $info); // $i = 0; // foreach ($list as $v) { // $v = trim($v); // $v = trim(str_replace(' ', '', $v), '

'); // if ($i == 0 && !empty($v)) { // $record['city'] = $v; // $key = $record['city']; // $list1[$key][] = $record; // } else { // if (!empty($v)) { // $data = explode(' ', $v); // $add_data = explode('市', $data[0]); // $record['city'] = mb_substr($add_data[0], 2); // $record['supply'] = $add_data[1]; // $record['ip'] = ''; // $record['daikuan'] = ''; // $record['onlineuser'] = ''; // $record['maxuser'] = ''; // $record['online'] = ''; // $record['status'] = ''; // $record['nasname'] = $data[count($data) - 1]; // if (!in_array($record['nasname'], $exit) && !in_array($record['nasname'], $dnx_has_exit)) { // fputcsv($dnx_exit, ['实惠', $record['nasname'], date('Y-m-d H:i:s')]); // } // $list1[$key][] = $record; // } // } // $i++; // } // } // } // foreach ($list1 as $val) { // foreach ($val as $net_data) { // fputcsv($file, $net_data); // fputcsv($all, $net_data); // } // } } //共享 function gongxiang_getList($html, &$file, &$all, $exit, $pro = '共享') { global $dnx_exit, $dnx_has_exit; //省会 $province = ['黑龙', '内蒙']; $province_record = []; $key = ''; $list1 = []; preg_match_all("//is", $html, $result); foreach ($result[0] as $k => $info) { $record = []; $record['name'] = $pro; $records['name'] = $pro; if ($k == 0) { continue; } else { preg_match_all("/(.*?)<\/td>/is", $info, $result); $info = $result[0]; foreach ($info as $i => $v) { $info[$i] = ltrim($info[$i], ''); $info[$i] = rtrim($info[$i], ''); } $nasname = $info[1]; $data[1] = $info[2]; if (strpos($data[1], '电信') !== false) { $supply = '电信'; $data[1] = mb_substr($data[1], 0, mb_strlen($data[1]) - 2); } elseif (strpos($data[1], '联通') !== false) { $supply = '联通'; $data[1] = mb_substr($data[1], 0, mb_strlen($data[1]) - 2); } elseif (strpos($data[1], '移动') !== false) { $supply = '移动'; $data[1] = mb_substr($data[1], 0, mb_strlen($data[1]) - 2); } else { $supply = '电信/联通'; } if (mb_strlen($data[1]) <= 3) { if (!in_array($data[1], $province_record)) { $record['city'] = $data[1]; $record['supply'] = $supply; $record['ip'] = ''; $record['daikuan'] = ''; $record['onlineuser'] = ''; $record['maxuser'] = ''; $record['online'] = strpos($info[4], '在线') ? '正常' : '故障'; $record['status'] = ''; $record['nasname'] = $nasname; $records['city'] = $data[1]; $province_record[] = $data[1]; if (in_array($record['city'], ['曾', '龙'])) { continue; } $key = $record['city']; $list1[$key][] = $records; $list1[$key][] = $record; } else { $record['city'] = $data[1]; $record['supply'] = $supply; $record['ip'] = ''; $record['daikuan'] = ''; $record['onlineuser'] = ''; $record['maxuser'] = ''; $record['online'] = strpos($info[4], '在线') ? '正常' : '故障'; $record['status'] = ''; $record['nasname'] = $nasname; if (in_array($record['city'], ['曾', '龙'])) { continue; } $list1[$key][] = $record; } } else { $province_detail = mb_substr($data['1'], 0, 2); if (in_array($province_detail, $province)) { $province_detail = mb_substr($data['1'], 0, 3); $key = $province_detail; if (in_array($province_detail, $province_record)) { $record['city'] = mb_substr($data['1'], 3); $record['supply'] = $supply; $record['ip'] = ''; $record['daikuan'] = ''; $record['onlineuser'] = ''; $record['maxuser'] = ''; $record['online'] = strpos($info[4], '在线') ? '正常' : '故障'; $record['status'] = ''; $record['nasname'] = $nasname; if (in_array($record['city'], ['曾', '龙'])) { continue; } $list1[$key][] = $record; } else { $record['city'] = mb_substr($data['1'], 3); $record['supply'] = $supply; $record['ip'] = ''; $record['daikuan'] = ''; $record['onlineuser'] = ''; $record['maxuser'] = ''; $record['online'] = strpos($info[4], '在线') ? '正常' : '故障'; $record['status'] = ''; $record['nasname'] = $nasname; $records['city'] = $province_detail; $province_record[] = $province_detail; if (in_array($record['city'], ['曾', '龙'])) { continue; } $list1[$key][] = $records; $list1[$key][] = $record; } } else { $province_detail = mb_substr($data['1'], 0, 2); $key = $province_detail; if (in_array($province_detail, $province_record)) { $record['city'] = mb_substr($data['1'], 2); $record['supply'] = $supply; $record['ip'] = ''; $record['daikuan'] = ''; $record['onlineuser'] = ''; $record['maxuser'] = ''; $record['online'] = strpos($info[4], '在线') ? '正常' : '故障'; $record['status'] = ''; $record['nasname'] = $nasname; if (in_array($record['city'], ['曾', '龙'])) { continue; } $list1[$key][] = $record; } else { $record['city'] = mb_substr($data['1'], 2); $record['supply'] = $supply; $record['ip'] = ''; $record['daikuan'] = ''; $record['onlineuser'] = ''; $record['maxuser'] = ''; $record['online'] = strpos($info[4], '在线') ? '正常' : '故障'; $record['status'] = ''; $record['nasname'] = $nasname; $records['city'] = $province_detail; $province_record[] = $province_detail; if (in_array($record['city'], ['曾', '龙'])) { continue; } $list1[$key][] = $records; $list1[$key][] = $record; } } } } } foreach ($list1 as $val) { foreach ($val as $net_data) { $net_data['city'] = str_replace('电信', '', $net_data['city']); $net_data['city'] = str_replace('联通', '', $net_data['city']); fputcsv($file, $net_data); fputcsv($all, $net_data); } } } function xunlian_getList($data, &$file, &$all, $exit) { global $dnx_exit, $dnx_has_exit; $online = ['故障', '正常']; $province = ['黑龙', '内蒙']; $citys = ['北京', '上海', '天津', '重庆']; $key = ''; $list1 = []; $province_record = []; foreach ($data as $info) { $record = []; $record['name'] = '讯连'; $province_detail = mb_substr($info['description'], 0, 2); if ($province_detail == '全国') { $record['city'] = $info['description']; if (!in_array('混播', $province_record)) { $province_record[] = '混播'; $key = '混播'; $list1[$key][] = $record; } $record['supply'] = '电信/联通'; } else { if (in_array($province_detail, $province)) { $province_detail = mb_substr($info['description'], 0, 3); $info['description'] = mb_substr($info['description'], 3); } elseif (!in_array($province_detail, $citys)) { $info['description'] = mb_substr($info['description'], 2); } if (!in_array($province_detail, $province_record)) { $record['city'] = $province_detail; $province_record[] = $province_detail; $key = $province_detail; $list1[$key][] = $record; } $key = $province_detail; if (strpos($info['description'], '电信') !== false) { $record['city'] = mb_substr($info['description'], 0, mb_strlen($info['description']) - 2); $record['supply'] = '电信'; } elseif (strpos($info['description'], '联通') !== false) { $record['city'] = mb_substr($info['description'], 0, mb_strlen($info['description']) - 2); $record['supply'] = '联通'; } elseif (strpos($info['description'], '移动') !== false) { $record['city'] = mb_substr($info['description'], 0, mb_strlen($info['description']) - 2); $record['supply'] = '移动'; } else { $record['city'] = $info['description']; $record['supply'] = '电信/联通'; } } if (strpos($record['city'], '省') !== false) { $record['city'] = mb_substr($record['city'], 1, mb_strlen($info['description'])); } for ($i = 1; $i < 6; $i++) { if (!empty($info['nasname' . $i])) { $record['ip'] = ''; if ($i == 1) { $record['daikuan'] = $info['maxbands'] ?: $info['description2']; } else { $record['daikuan'] = $info['maxbands' . ($i - 1)] ?: $info['description2']; } $record['onlineuser'] = ''; $record['maxuser'] = ''; $record['online'] = $online[$info['online']]; $record['status'] = ''; $record['nasname'] = $info['nasname' . $i]; if (!in_array($record['nasname'], $exit) && !in_array($record['nasname'], $dnx_has_exit)) { fputcsv($dnx_exit, ['讯连', $record['nasname'], date('Y-m-d H:i:s')]); } $list1[$key][] = $record; } } } foreach ($list1 as $val) { foreach ($val as $net_data) { fputcsv($file, $net_data); fputcsv($all, $net_data); } } } function wuxian_getList($html, &$file, &$all, $exit) { // global $dnx_exit, $dnx_has_exit; // //省会 // $province = ['黑龙', '内蒙']; // $province_record = []; // $key = ''; // $list1 = []; // $citys = ['北京', '上海', '天津', '重庆']; // preg_match("/
 <\/div>(.*?)<\/div><\/div>/is", $html, $result); // $result = str_replace('
 
', '', $result[0]); // preg_match_all("/
(.*?)<\/div>/is", $result, $result); // foreach ($result[0] as $k => $info) { // $record = []; // $record['name'] = '无限'; // $info = ltrim($info, '
'); // $info = rtrim($info, '
'); // if (strpos($info, 'span') !== false) { // $data = explode(' ', $info); // } else { // $data = explode('            ', $info); // } // $data[1] = trim($data[1]); // $province_detail = mb_substr(trim($data[1]), 0, 2); // if (in_array($province_detail, $province)) { // $province_detail = mb_substr($data[1], 0, 3); // $data[1] = mb_substr($data[1], 3); // } elseif (!in_array($province_detail, $citys)) { // $data[1] = mb_substr($data[1], 2); // } // if (!in_array($province_detail, $province_record)) { // $record['city'] = $province_detail; // $province_record[] = $province_detail; // $key = $record['city']; // $list1[$key][] = $record; // } // if (strpos($data[1], '电信') !== false) { // $record['city'] = explode('电信', $data[1])[0]; // $record['city'] = str_replace('<', '', $record['city']); // $record['city'] = str_replace('>', '', $record['city']); // $record['supply'] = '电信'; // } elseif (strpos($data[1], '联通') !== false) { // $record['city'] = explode('联通', $data[1])[0]; // $record['city'] = str_replace('<', '', $record['city']); // $record['city'] = str_replace('>', '', $record['city']); // $record['supply'] = '联通'; // } elseif (strpos($data[1], '移动') !== false) { // $record['city'] = explode('移动', $data[1])[0]; // $record['city'] = str_replace('<', '', $record['city']); // $record['city'] = str_replace('>', '', $record['city']); // $record['supply'] = '移动'; // } else { // $record['city'] = $data[1]; // $record['city'] = str_replace('<', '', $record['city']); // $record['city'] = str_replace('>', '', $record['city']); // $record['supply'] = '电信/联通'; // } // $record['ip'] = ''; // $record['daikuan'] = ''; // $record['onlineuser'] = ''; // $record['maxuser'] = ''; // $record['online'] = ''; // $record['status'] = ''; // $record['nasname'] = $data[0]; // if (!in_array($record['nasname'], $exit) && !in_array($record['nasname'], $dnx_has_exit)) { // fputcsv($dnx_exit, ['无限', $record['nasname'], date('Y-m-d H:i:s')]); // } // $list1[$key][] = $record; // } // foreach ($list1 as $val) { // foreach ($val as $net_data) { // $net_data['city'] = str_replace('电信', '', $net_data['city']); // $net_data['city'] = str_replace('联通', '', $net_data['city']); // fputcsv($file, $net_data); // fputcsv($all, $net_data); // } // } } function xianfeng_getList($data, &$file, &$all, $exit) { global $dnx_exit, $dnx_has_exit; //省会 $province = ['黑龙', '内蒙', '直辖']; $province_record = []; $key = ''; $list1 = []; $status = ['维护中', '正常']; foreach ($data as $info) { $record = []; $record['name'] = '先锋'; $info['description'] = trim($info['description'], 'a'); if (strpos($info['description'], '混播') || strpos($info['description'], '所有单城市')) { $province_detail = '混播'; if (!in_array($province_detail, $province_record)) { $record['city'] = $province_detail; $province_record[] = $province_detail; $key = $record['city']; $list1[$key][] = $record; } $record['city'] = $info['description']; $record['supply'] = '电信/联通'; } else { $province_detail = mb_substr(trim($info['description']), 0, 2); if (in_array($province_detail, $province)) { $province_detail = mb_substr($info['description'], 0, 3); } if (!in_array($province_detail, $province_record)) { $record['city'] = $province_detail; $province_record[] = $province_detail; $key = $record['city']; $list1[$key][] = $record; } $key = $province_detail; if (strpos($info['description'], '电信') !== false) { $record['city'] = $info['description']; $record['supply'] = '电信'; } elseif (strpos($info['description'], '联通') !== false) { $record['city'] = $info['description']; $record['supply'] = '联通'; } elseif (strpos($info['description'], '移动') !== false) { $record['city'] = $info['description']; $record['supply'] = '移动'; } else { $record['city'] = $info['description']; $record['supply'] = '电信/联通'; } } $record['ip'] = ''; $record['daikuan'] = $info['description2']; $record['onlineuser'] = $info['onlineuser']; $record['maxuser'] = $info['maxuser']; $record['online'] = ($info['status'] == 1) ? '正常' : '故障'; $status_flag = $info['onlineuser'] / $info['maxuser']; $record['status'] = ''; if ($status_flag < 0.9) { $record['status'] = '正常'; } elseif ($status_flag < 0.1) { $record['status'] = '拥挤'; } else { $record['status'] = '满载'; } $record['nasname'] = $info['nasname']; if (!in_array($record['nasname'], $exit) && !in_array($record['nasname'], $dnx_has_exit)) { fputcsv($dnx_exit, ['先锋', $record['nasname'], date('Y-m-d H:i:s')]); } $list1[$key][] = $record; } foreach ($list1 as $val) { foreach ($val as $net_data) { $net_data['city'] = str_replace('电信', '', $net_data['city']); $net_data['city'] = str_replace('联通', '', $net_data['city']); if (mb_strlen($net_data['city']) > 3 && !strpos($net_data['city'], '省内')) { $net_data['city'] = mb_substr($net_data['city'], 3); } fputcsv($file, $net_data); fputcsv($all, $net_data); } } } function jinrui_getList($html, &$file, &$all, $exit) { global $dnx_exit, $dnx_has_exit; //省会 $province_record = []; $key = ''; $list1 = []; preg_match_all("/\{(.*?)\}/is", $html, $result); foreach ($result[0] as $info) { $info = json_decode($info, true); if (empty($info)) { continue; } $record = []; $record['name'] = '金瑞'; if (!in_array($info['province'], $province_record)) { $record['city'] = $info['province']; $province_record[] = $info['province']; $key = $record['city']; $list1[$key][] = $record; } if (empty($info['city'])) { $record['city'] = $info['province']; } else { $record['city'] = $info['city']; } $record['supply'] = $info['isp']; $record['ip'] = ''; $record['daikuan'] = ''; $record['onlineuser'] = ''; $record['maxuser'] = ''; $record['online'] = $info['status'] == 1 ? '正常' : '故障'; $record['status'] = ''; $nasname = explode('|', $info['nasname']); foreach ($nasname as $v) { $record['nasname'] = $v; if (!in_array($record['nasname'], $exit) && !in_array($record['nasname'], $dnx_has_exit)) { fputcsv($dnx_exit, ['金瑞', $record['nasname'], date('Y-m-d H:i:s')]); } $list1[$info['province']][] = $record; } } foreach ($list1 as $val) { foreach ($val as $net_data) { fputcsv($file, $net_data); fputcsv($all, $net_data); } } } function get_content($url, $cookie) { $product_model = new Product; $product_token = $product_model->where(['Id'=>18])->field('Id,Token')->fetch()['Token']; $header = [ 'Authorization: Bearer '.$product_token, ]; // print_r($header); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_HTTPHEADER, $header); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_COOKIE, $cookie); //读取cookie $rs = curl_exec($ch); //执行cURL抓取页面内容 // print_r($rs); curl_close($ch); return $rs; } function get_product($file_path, $num = 9) { $list = []; $file = fopen($file_path, 'r'); while ($info = fgetcsv($file)) { if (isset($info[$num])) { $list[] = $info[$num]; } } fclose($file); return $list; } function xianfeng_post($url, $cookie, $post) { $curl = curl_init(); //初始化curl模块 curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_HEADER, 0); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_COOKIE, $cookie); //读取cookie curl_setopt($curl, CURLOPT_POST, 1); //post方式提交 curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($post)); //要提交的信息 $rs = curl_exec($curl); //执行cURL抓取页面内容 curl_close($curl); return $rs; }