服务器列表

This commit is contained in:
wanyongkang
2020-11-13 15:20:04 +08:00
parent 2601efa3aa
commit 6ada8cd167
2 changed files with 515 additions and 477 deletions

View File

@@ -5,7 +5,7 @@
* @Author: kangkang * @Author: kangkang
* @Date: 2020-11-06 14:32:57 * @Date: 2020-11-06 14:32:57
* @LastEditors: kangkang * @LastEditors: kangkang
* @LastEditTime: 2020-11-12 09:38:30 * @LastEditTime: 2020-11-12 17:14:34
*/ */
header('Access-Control-Allow-Origin: *'); header('Access-Control-Allow-Origin: *');
header("Access-Control-Allow-Methods: *"); header("Access-Control-Allow-Methods: *");
@@ -51,10 +51,12 @@ switch($id){
break; break;
} }
function format_all_product($file_path){ function format_all_product($file_path)
{
$list = []; $list = [];
$dns = ''; $dns = '';
$record = []; $record = [];
$citys = [];
$user_count = 0; $user_count = 0;
$count = 0; $count = 0;
$file = fopen($file_path, 'r'); $file = fopen($file_path, 'r');
@@ -96,7 +98,9 @@ function format_all_product($file_path){
$dns = 'shihui'; $dns = 'shihui';
break; break;
} }
$data['city'] = $info[1]; $city = city_exist($citys,$info[1]);
$citys[] = $city;
$data['city'] = $city;
$data['supply'] = $info[2]; $data['supply'] = $info[2];
$data['ip'] = $info[3]; $data['ip'] = $info[3];
$data['daikuan'] = $info[4]; $data['daikuan'] = $info[4];
@@ -122,12 +126,14 @@ function format_all_product($file_path){
echo json_encode(['data' => $list, 'count' => $count, 'use_count' => $user_count]); echo json_encode(['data' => $list, 'count' => $count, 'use_count' => $user_count]);
} }
function format_product($file_path,$dns = ''){ function format_product($file_path, $dns = '')
{
$list1 = []; $list1 = [];
$list = []; $list = [];
$user_count = 0; $user_count = 0;
$count = 0; $count = 0;
$key = ''; $key = '';
$citys = [];
$file = fopen($file_path, 'r'); $file = fopen($file_path, 'r');
$file_path1 = explode('/', $file_path); $file_path1 = explode('/', $file_path);
$file1 = fopen(__DIR__ . '/data/download/' . $file_path1[8], 'w'); $file1 = fopen(__DIR__ . '/data/download/' . $file_path1[8], 'w');
@@ -140,7 +146,9 @@ function format_product($file_path,$dns = ''){
$key = $info[1]; $key = $info[1];
} }
$data['name'] = $info[0]; $data['name'] = $info[0];
$data['city'] = $info[1]; $city = city_exist($citys,$info[1]);
$citys[] = $city;
$data['city'] = $city;
$data['supply'] = $info[2]; $data['supply'] = $info[2];
$data['ip'] = $info[3]; $data['ip'] = $info[3];
$data['daikuan'] = $info[4]; $data['daikuan'] = $info[4];
@@ -174,12 +182,14 @@ function format_product($file_path,$dns = ''){
echo json_encode(['data' => $list, 'count' => $count, 'use_count' => $user_count]); echo json_encode(['data' => $list, 'count' => $count, 'use_count' => $user_count]);
} }
function format_xingxing($file_path1,$file_path2,$dns){ function format_xingxing($file_path1, $file_path2, $dns)
{
$list1 = []; $list1 = [];
$list = []; $list = [];
$user_count = 0; $user_count = 0;
$count = 0; $count = 0;
$key = ''; $key = '';
$citys = [];
$file1 = fopen($file_path1, 'r'); $file1 = fopen($file_path1, 'r');
$file2 = fopen($file_path2, 'r'); $file2 = fopen($file_path2, 'r');
$record = []; $record = [];
@@ -193,7 +203,9 @@ function format_xingxing($file_path1,$file_path2,$dns){
$keys[] = $key; $keys[] = $key;
} }
$data['name'] = $info[0]; $data['name'] = $info[0];
$data['city'] = $info[1]; $city = city_exist($citys,$info[1]);
$citys[] = $city;
$data['city'] = $city;
$data['supply'] = $info[2]; $data['supply'] = $info[2];
$data['ip'] = $info[3]; $data['ip'] = $info[3];
$data['daikuan'] = $info[4]; $data['daikuan'] = $info[4];
@@ -217,7 +229,9 @@ function format_xingxing($file_path1,$file_path2,$dns){
} }
} }
$data['name'] = $info[0]; $data['name'] = $info[0];
$data['city'] = $info[1]; $city = city_exist($citys,$info[1]);
$citys[] = $city;
$data['city'] = $city;
$data['supply'] = $info[2]; $data['supply'] = $info[2];
$data['ip'] = $info[3]; $data['ip'] = $info[3];
$data['daikuan'] = $info[4]; $data['daikuan'] = $info[4];
@@ -246,11 +260,11 @@ function format_xingxing($file_path1,$file_path2,$dns){
fclose($file2); fclose($file2);
fclose($file3); fclose($file3);
echo json_encode(['data' => $list, 'count' => $count, 'use_count' => $user_count]); echo json_encode(['data' => $list, 'count' => $count, 'use_count' => $user_count]);
} }
function ip_repeat(&$record,$ip){ function ip_repeat(&$record, $ip)
{
for ($i = 2; $i < 100; $i++) { for ($i = 2; $i < 100; $i++) {
if (in_array($ip, $record)) { if (in_array($ip, $record)) {
if (in_array($ip . 'v' . $i, $record)) { if (in_array($ip . 'v' . $i, $record)) {
@@ -265,3 +279,18 @@ function ip_repeat(&$record,$ip){
} }
} }
} }
function city_exist($citys, $city)
{
for ($i = 2; $i < 100; $i++) {
if (in_array($city, $citys)) {
if (in_array($city . $i, $citys)) {
continue;
} else {
return $city . $i;
}
} else {
return $city;
}
}
}

View File

@@ -5,18 +5,15 @@
* @Author: kangkang * @Author: kangkang
* @Date: 2020-11-03 11:04:15 * @Date: 2020-11-03 11:04:15
* @LastEditors: kangkang * @LastEditors: kangkang
* @LastEditTime: 2020-11-12 11:09:15 * @LastEditTime: 2020-11-13 15:19:10
*/ */
$is_script = 1; $is_script = 1;
include __DIR__ . '/../../index.php'; include __DIR__ . '/../../index.php';
use app\api\model\Product; use app\api\model\Product;
$product_model = new Product; $product_model = new Product;
$product_list = $product_model->field('Id,Token')->fetchAll(); $product_list = $product_model->field('Id,Token')->fetchAll();
$all = fopen(__DIR__ . '/data/all.csv', 'w'); $all = fopen(__DIR__ . '/data/all.csv', 'w');
$dnx_exit = fopen(__DIR__ . '/data/dns_diff.csv', 'a'); $dnx_exit = fopen(__DIR__ . '/data/dns_diff.csv', 'a');
$dnx_has_exit = get_product(__DIR__ . '/data/dns_diff.csv', 1); $dnx_has_exit = get_product(__DIR__ . '/data/dns_diff.csv', 1);
@@ -85,7 +82,7 @@ fclose($wuxian_f);
$xianfeng_data = get_product(__DIR__ . '/data/xianfeng.csv'); $xianfeng_data = get_product(__DIR__ . '/data/xianfeng.csv');
$xianfeng_f = fopen(__DIR__ . '/data/xianfeng.csv', 'w'); $xianfeng_f = fopen(__DIR__ . '/data/xianfeng.csv', 'w');
$xianfeng = json_decode(xianfeng_post('http://39.102.54.40/development/fault.html','PHPSESSID=0o1144geu80ocep2obta68o3o1',['page'=>1,'limit'=>1000]),true)['data']; $xianfeng = json_decode(file_get_contents("http://apiserver.pptp.biz/Apiserver/getserver"), true);
//写入先锋文件 //写入先锋文件
xianfeng_getList($xianfeng, $xianfeng_f, $all, $xianfeng_data); xianfeng_getList($xianfeng, $xianfeng_f, $all, $xianfeng_data);
fclose($xianfeng_f); fclose($xianfeng_f);
@@ -150,7 +147,6 @@ function qiangzi_getList($data,&$file,&$all,$exit)
$record['online'] = $info['online'] == 1 ? '正常' : '故障'; $record['online'] = $info['online'] == 1 ? '正常' : '故障';
$record['status'] = $status[$info['status']]; $record['status'] = $status[$info['status']];
if (strpos($info['description'], '省混')) { if (strpos($info['description'], '省混')) {
$record['nasname'] = $info['nasname']; $record['nasname'] = $info['nasname'];
if (!in_array($record['nasname'], $exit) && !in_array($record['nasname'], $dnx_has_exit)) { if (!in_array($record['nasname'], $exit) && !in_array($record['nasname'], $dnx_has_exit)) {
@@ -345,7 +341,8 @@ function tiantian_getList($data,&$file,&$all,$exit,$product_name)
} }
function shihui_getList($html,&$file,&$all,$exit){ function shihui_getList($html, &$file, &$all, $exit)
{
global $dnx_exit, $dnx_has_exit; global $dnx_exit, $dnx_has_exit;
$key = ''; $key = '';
$list1 = []; $list1 = [];
@@ -400,7 +397,8 @@ function shihui_getList($html,&$file,&$all,$exit){
} }
//共享 //共享
function gongxiang_getList($html,&$file,&$all,$exit,$pro = '共享'){ function gongxiang_getList($html, &$file, &$all, $exit, $pro = '共享')
{
global $dnx_exit, $dnx_has_exit; global $dnx_exit, $dnx_has_exit;
//省会 //省会
$province = ['黑龙', '内蒙']; $province = ['黑龙', '内蒙'];
@@ -549,7 +547,6 @@ function gongxiang_getList($html,&$file,&$all,$exit,$pro = '共享'){
foreach ($list1 as $val) { foreach ($list1 as $val) {
foreach ($val as $net_data) { foreach ($val as $net_data) {
$net_data['city'] = str_replace('电信', '', $net_data['city']); $net_data['city'] = str_replace('电信', '', $net_data['city']);
$net_data['city'] = str_replace('联通', '', $net_data['city']); $net_data['city'] = str_replace('联通', '', $net_data['city']);
@@ -559,7 +556,8 @@ function gongxiang_getList($html,&$file,&$all,$exit,$pro = '共享'){
} }
} }
function xunlian_getList($data,&$file,&$all,$exit){ function xunlian_getList($data, &$file, &$all, $exit)
{
global $dnx_exit, $dnx_has_exit; global $dnx_exit, $dnx_has_exit;
$online = ['故障', '正常']; $online = ['故障', '正常'];
$province = ['黑龙', '内蒙']; $province = ['黑龙', '内蒙'];
@@ -614,7 +612,6 @@ function xunlian_getList($data,&$file,&$all,$exit){
for ($i = 1; $i < 6; $i++) { for ($i = 1; $i < 6; $i++) {
if (!empty($info['nasname' . $i])) { if (!empty($info['nasname' . $i])) {
$record['ip'] = ''; $record['ip'] = '';
if ($i == 1) { if ($i == 1) {
$record['daikuan'] = $info['maxbands'] ?: $info['description2']; $record['daikuan'] = $info['maxbands'] ?: $info['description2'];
@@ -642,7 +639,8 @@ function xunlian_getList($data,&$file,&$all,$exit){
} }
} }
function wuxian_getList($html,&$file,&$all,$exit){ function wuxian_getList($html, &$file, &$all, $exit)
{
global $dnx_exit, $dnx_has_exit; global $dnx_exit, $dnx_has_exit;
//省会 //省会
$province = ['黑龙', '内蒙']; $province = ['黑龙', '内蒙'];
@@ -712,21 +710,20 @@ function wuxian_getList($html,&$file,&$all,$exit){
} }
$list1[$key][] = $record; $list1[$key][] = $record;
} }
foreach ($list1 as $val) { foreach ($list1 as $val) {
foreach ($val as $net_data) { foreach ($val as $net_data) {
$net_data['city'] = str_replace('电信', '', $net_data['city']); $net_data['city'] = str_replace('电信', '', $net_data['city']);
$net_data['city'] = str_replace('联通', '', $net_data['city']); $net_data['city'] = str_replace('联通', '', $net_data['city']);
fputcsv($file, $net_data); fputcsv($file, $net_data);
fputcsv($all, $net_data); fputcsv($all, $net_data);
} }
} }
} }
function xianfeng_getList($data,&$file,&$all,$exit){ function xianfeng_getList($data, &$file, &$all, $exit)
{
global $dnx_exit, $dnx_has_exit; global $dnx_exit, $dnx_has_exit;
//省会 //省会
$province = ['黑龙', '内蒙', '直辖']; $province = ['黑龙', '内蒙', '直辖'];
@@ -775,11 +772,19 @@ function xianfeng_getList($data,&$file,&$all,$exit){
} }
} }
$record['ip'] = ''; $record['ip'] = '';
$record['daikuan'] = ''; $record['daikuan'] = $info['description2'];
$record['onlineuser'] = ''; $record['onlineuser'] = $info['onlineuser'];
$record['maxuser'] = ''; $record['maxuser'] = $info['maxuser'];
$record['online'] = ($info['serstatus'] == 1)?'正常':'故障'; $record['online'] = ($info['status'] == 1) ? '正常' : '故障';
$status_flag = $info['onlineuser'] / $info['maxuser'];
$record['status'] = ''; $record['status'] = '';
if ($status_flag < 0.9) {
$record['status'] = '正常';
} elseif ($status_flag < 0.95) {
$record['status'] = '拥挤';
} else {
$record['status'] = '满载';
}
$record['nasname'] = $info['nasname']; $record['nasname'] = $info['nasname'];
if (!in_array($record['nasname'], $exit) && !in_array($record['nasname'], $dnx_has_exit)) { 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')]); fputcsv($dnx_exit, ['先锋', $record['nasname'], date('Y-m-d H:i:s')]);
@@ -792,7 +797,9 @@ function xianfeng_getList($data,&$file,&$all,$exit){
$net_data['city'] = str_replace('电信', '', $net_data['city']); $net_data['city'] = str_replace('电信', '', $net_data['city']);
$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); 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($file, $net_data);
fputcsv($all, $net_data); fputcsv($all, $net_data);
@@ -800,8 +807,8 @@ function xianfeng_getList($data,&$file,&$all,$exit){
} }
} }
function jinrui_getList($html, &$file, &$all, $exit)
function jinrui_getList($html,&$file,&$all,$exit){ {
global $dnx_exit, $dnx_has_exit; global $dnx_exit, $dnx_has_exit;
//省会 //省会
$province_record = []; $province_record = [];
@@ -845,14 +852,14 @@ function jinrui_getList($html,&$file,&$all,$exit){
foreach ($list1 as $val) { foreach ($list1 as $val) {
foreach ($val as $net_data) { foreach ($val as $net_data) {
fputcsv($file, $net_data); fputcsv($file, $net_data);
fputcsv($all, $net_data); fputcsv($all, $net_data);
} }
} }
} }
function get_content($url, $cookie) { function get_content($url, $cookie)
{
$ch = curl_init(); $ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_HEADER, 0);
@@ -863,20 +870,22 @@ function get_content($url, $cookie) {
return $rs; return $rs;
} }
function get_product($file_path,$num = 9){ function get_product($file_path, $num = 9)
{
$list = []; $list = [];
$file = fopen($file_path, 'r'); $file = fopen($file_path, 'r');
while ($info = fgetcsv($file)) { while ($info = fgetcsv($file)) {
if(isset($info[$num])) if (isset($info[$num])) {
$list[] = $info[$num]; $list[] = $info[$num];
} }
}
fclose($file); fclose($file);
return $list; return $list;
} }
function xianfeng_post($url, $cookie, $post)
{
function xianfeng_post($url, $cookie, $post) {
$curl = curl_init(); //初始化curl模块 $curl = curl_init(); //初始化curl模块
curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, 0); curl_setopt($curl, CURLOPT_HEADER, 0);