-
Notifications
You must be signed in to change notification settings - Fork 1
/
ping-cli.php
90 lines (73 loc) · 2.56 KB
/
ping-cli.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
$waitTimeoutInSeconds = 1;
$ports = [80, 443];
$hosts = [
'example.com',
'103.26.139.87',
'sandbox.sslcommerz.com',
'103.26.139.148',
'securepay.sslcommerz.com',
];
echo system_info();
test_ports($ports, $hosts);
# Function Definitions #
function newline($n = 1)
{
$return = "";
foreach (range(1, $n) as $i) {
$return .= PHP_EOL;
}
return $return;
}
function server_ip_address()
{
$ch = curl_init('https://httpbin.org/ip');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
if (!$response || !($data = json_decode($response)) || !isset($data->origin)) {
return "Unable to fetch server IP address." . newline();
}
return "Server IP Address is: " . htmlspecialchars($data->origin, ENT_QUOTES, 'UTF-8') . newline();
}
function system_info()
{
$return = "";
$return .= "PHP version: " . htmlspecialchars(phpversion(), ENT_QUOTES, 'UTF-8') . newline();
if (function_exists('curl_version')) {
$return .= server_ip_address();
$curl_version = curl_version();
$return .= "cURL version: " . htmlspecialchars($curl_version['version'], ENT_QUOTES, 'UTF-8')."" . newline();
$return .= "openSSL version: " . htmlspecialchars($curl_version['ssl_version'], ENT_QUOTES, 'UTF-8')."" . newline();
$return .= tls_info() . newline();
} else {
$return .= "Curl extension is disabled. Please enable it from cpanel/php.ini or contact your hosting provider." . newline();
}
return $return . newline();
}
function tls_info()
{
$ch = curl_init('https://www.howsmyssl.com/a/check');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($ch);
curl_close($ch);
if (!$data) return "Error fetching data." . newline(2);
$json = json_decode($data);
if (!$json || !isset($json->tls_version)) return "Error: Could not retrieve TLS version." . newline(2);
return "Server can support TLS version up to " . htmlspecialchars($json->tls_version, ENT_QUOTES, 'UTF-8') . " *not reliable";
}
function test_ports($ports, $hosts)
{
global $waitTimeoutInSeconds;
foreach ($hosts as $host) {
foreach ($ports as $port) {
if ($fp = @fsockopen($host, $port, $errCode, $errStr, $waitTimeoutInSeconds)) {
echo "connected to $host on port $port" . newline();
fclose($fp);
} else {
echo "failed to connect to $host on port $port ($errCode : $errStr)" . newline();
}
}
echo newline();
}
}