API to test TCP connections
This commit is contained in:
parent
75d4fa1081
commit
a8128d1a00
|
@ -0,0 +1,21 @@
|
|||
<?php chdir('../../../../') ?>
|
||||
<?php require 'base.php' ?>
|
||||
<?php
|
||||
|
||||
$uri = trim($_GET['uri']);
|
||||
if (!preg_match('/^\d+\.\d+\.\d+\.\d+:\d+$/', $uri)) {
|
||||
http_response_code(400);
|
||||
apiresult(['error' => 'The given URI must match IPV4_HOST:PORT scheme']);
|
||||
}
|
||||
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, "http://$uri");
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_exec($ch);
|
||||
$error_msg = curl_error($ch);
|
||||
curl_close($ch);
|
||||
|
||||
if (strpos(strtolower($error_msg), 'connection refused'))
|
||||
apiresult(['error' => 'Could not connect to host: '.$uri]);
|
||||
|
||||
apiresult(['status' => 'ok']);
|
Loading…
Reference in New Issue