Skip to content

Commit

Permalink
https://github.com/WWBN/AVideo/issues/9167
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Neto committed Jun 30, 2024
1 parent 5e7cba5 commit 183e64d
Showing 1 changed file with 37 additions and 2 deletions.
39 changes: 37 additions & 2 deletions plugin/YPTSocket/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,22 @@
$address = $socketobj->host;
$port = $socketobj->port;
$socketobj->forceNonSecure = false;


if (!isPortOpen('127.0.0.1', $port)) {
_log("Port {$port} is not open on localhost");
die();
}

if (!isDomainResolving($address)) {
_log("Domain {$address} is not resolving");
die();
}

if (!isPortOpen($address, $port)) {
_log("Port {$port} is not open on {$address}");
die();
}

$url = "://localhost:{$port}";
$SocketURL = 'ws' . $url;
_test_send($SocketURL, 'ws');
Expand All @@ -45,6 +60,26 @@
_test_send($SocketURL, 'wss');
}

function isPortOpen($host, $port) {
$output = [];
$result = null;
exec("nc -zv {$host} {$port} 2>&1", $output, $result);
foreach ($output as $line) {
_log($line);
}
return $result === 0;
}

function isDomainResolving($domain) {
$output = [];
$result = null;
exec("nslookup {$domain} 2>&1", $output, $result);
foreach ($output as $line) {
_log($line);
}
return $result === 0;
}

function _test_send($SocketURL, $msg) {
global $SocketSendObj, $count;
$_count = $count;
Expand Down Expand Up @@ -213,4 +248,4 @@ function printIfComplete() {
*/
_log($msg);
}
}
}

0 comments on commit 183e64d

Please sign in to comment.