-
Notifications
You must be signed in to change notification settings - Fork 0
/
ping.php
42 lines (31 loc) · 1.02 KB
/
ping.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
<?php
header('Content-Type: application/json');
$domain = isset($_GET['domain']) ? $_GET['domain'] : '';
$timeout = 1;
$pingResult = pingDomain($domain, $timeout);
$whoisResult = getWhoisInfo($domain);
$response = [
'online' => $pingResult['online'],
'whois' => $whoisResult,
];
echo json_encode($response);
function pingDomain($domain, $timeout) {
$file = @fsockopen($domain, 80, $errno, $errstr, $timeout);
// Check if the connection is successful
$online = is_resource($file);
if ($online) {
fclose($file);
}
return ['online' => $online];
}
function getWhoisInfo($domain) {
$apiKey = 'at_gg6IpQE8A2zOHWPyaXa2BCzHhOHIW'; // Ganti dengan kunci API Anda
$whoisUrl = "https://www.whoisxmlapi.com/whoisserver/WhoisService?apiKey={$apiKey}&domainName={$domain}&outputFormat=json";
$response = file_get_contents($whoisUrl);
if ($response === false) {
return ['error' => 'Gagal mengambil informasi WHOIS.'];
} else {
return json_decode($response, true);
}
}
?>