From 5ee8db35e8995a96b758d7260b934e5cd57b63a1 Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Tue, 27 Jun 2023 17:53:35 +0800 Subject: [PATCH] feat: vlmcs check interface --- web/vlmcs.php | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 web/vlmcs.php diff --git a/web/vlmcs.php b/web/vlmcs.php new file mode 100644 index 0000000..f33f54c --- /dev/null +++ b/web/vlmcs.php @@ -0,0 +1,57 @@ + ['pipe', 'r'], // stdin + 1 => ['pipe', 'w'], // stdout + 2 => ['pipe', 'w'], // stderr + ); + $process = proc_open($command, $desc, $pipes, null, array()); // start process + if (!is_resource($process)) { + throw new Exception('process running failed'); + } + while(proc_get_status($process)['running']) { // wait process exit + usleep(50); // delay 50ms + } + return stream_get_contents($pipes[1]); // fetch stdout +} + +function vlmcsCheck(string $host, int $port): VlmcsResult { + $host = str_contains($host, ':') ? "[$host]" : $host; // ipv6 host add bracket + try { + $content = runProcess(['vlmcs', $host . ':' . $port]); + } catch (Exception) { + return VlmcsResult::ERROR; + } + + preg_match_all('/Sending activation request \(KMS V6\)/', $content, $match); + if (count($match[0]) != 0) { + return VlmcsResult::OK; // kms server works fine + } + preg_match_all('/Connecting to .* successful/', $content, $match); + if (count($match[0]) != 0) { + return VlmcsResult::NOT_KMS; // server connected but not working + } else { + return VlmcsResult::UNREACHED; // kms server connect failed + } +} + +//$t = vlmcsCheck('1.1.1.1', 1688); +//$t = vlmcsCheck('kms.343.re', 1688); +$t = vlmcsCheck('8.210.148.24', 1688); +$t = vlmcsCheck('8.210.148.24', 1689); +//$t = vlmcsCheck('0.0.0.0.', 1688); +//$t = vlmcsCheck('baidu.com', 1688); +var_dump($t);