-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass.php
89 lines (72 loc) · 2.28 KB
/
class.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
<?php
header('Content-type: application/json');
class CheckHost
{
private $baseUrl = 'https://check-host.net';
private function Request($url)
{
$curl = curl_init();
curl_setopt_array(
$curl,
array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTPHEADER => array(
'Accept: application/json'
),
)
);
$response = curl_exec($curl);
curl_close($curl);
return $response;
}
private function check($checkType, $hostname, $maxNodes, $nodes = null)
{
$url = "{$this->baseUrl}/check-$checkType?host=$hostname&max_nodes=$maxNodes";
if ($nodes !== null) {
$nodesParam = is_array($nodes) ? implode('&node=', $nodes) : $nodes;
$url .= "&node=$nodesParam";
}
return $this->Request($url);
}
public function NodesIPs()
{
$url = "{$this->baseUrl}/nodes/ips";
return $this->Request($url);
}
public function NodesHosts()
{
$url = "{$this->baseUrl}/nodes/hosts";
return $this->Request($url);
}
public function checkTCP($hostname, $maxNodes, $nodes = null)
{
return $this->check('tcp', $hostname, $maxNodes, $nodes);
}
public function checkHTTP($hostname, $maxNodes, $nodes = null)
{
return $this->check('http', $hostname, $maxNodes, $nodes);
}
public function checkDNS($hostname, $maxNodes, $nodes = null)
{
return $this->check('dns', $hostname, $maxNodes, $nodes);
}
public function checkPing($hostname, $maxNodes, $nodes = null)
{
return $this->check('ping', $hostname, $maxNodes, $nodes);
}
public function checkUDP($hostname, $maxNodes, $nodes = null)
{
return $this->check('udp', $hostname, $maxNodes, $nodes);
}
public function getLink($requestId)
{
return "{$this->baseUrl}/check-report/$requestId";
}
public function CheckResult($requestId)
{
$url = "{$this->baseUrl}/check-result/$requestId";
return $this->Request($url);
}
}