From 66c393f34c559d8c63ba2af8e931d669f3b70096 Mon Sep 17 00:00:00 2001 From: Enoch Date: Sun, 10 Nov 2024 22:27:34 +0800 Subject: [PATCH] save --- src/Detect.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Detect.php b/src/Detect.php index bec9db6..d3f014e 100644 --- a/src/Detect.php +++ b/src/Detect.php @@ -6,11 +6,15 @@ use WebSocket\Client; class Detect { var $dest='ws://172.83.153.167:2345'; - public function getClassify(){ + public function getClassify($type=null){ if(!isset($this->classify)){ $this->classify(); } - return $this->classify; + if($type){ + return $this->classify[$type]; + }else{ + return $this->classify; + } } public function classify(){ if(!isset($this->ping)){ @@ -19,12 +23,17 @@ class Detect $classify = []; foreach($this->ping as $id=>$node){ $isp = $node['nodeinfo']->nodename; - $isp=explode(' ',$isp); + $isp = preg_replace('/\(.*?\)/', '', $isp); + + $isp=explode('-',$isp); if(in_array(end($isp),['电信','联通','移动','BGP'])){ $isp = '中国'.end($isp); }else{ $isp = $isp[0]; } + if(!isset($classify[$isp])){ + $classify[$isp]=[]; + } array_push($classify[$isp],$node); } $this->classify=$classify;