-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIPToHost.php
More file actions
65 lines (62 loc) · 1.75 KB
/
IPToHost.php
File metadata and controls
65 lines (62 loc) · 1.75 KB
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
<?php
require_once '../app/require.php';
$api = new APIController;
function getServerIP($host) {
$ip = gethostbyname($host);
return $ip === $host ? false : $ip;
}
// start key
if (isset($_GET['key']))
{
$statusCheck = $api->CheckKey($_GET['key'], $_SERVER['REQUEST_URI']);
// start statusCheck
if ($statusCheck === "valid")
{
// start host check
if (isset($_GET['host']))
{
$host = $_GET['host'];
$ip = getServerIP($host);
// start ip check
if ($ip !== false)
{
// start json check
if (isset($_GET['json']))
{
header("Content-Type: application/json");
$api->QueryLog($host, "GetIP", $_GET['key']);
echo json_encode(['host' => $host, 'ip' => $ip], JSON_PRETTY_PRINT);
}
else {
echo 'Host: ' . $host . ' | IP: ' . $ip . "\n";
$api->QueryLog($host, "GetIP", $_GET['key']);
}
// end json check
}
else {
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: *");
header("Content-Type: application/json");
echo json_encode(["error" => "Failed to get IP for host: $host"]);
}
// end ip check
}
else {
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: *");
header("Content-Type: application/json");
echo json_encode(["error" => "Missing 'host' parameter"]);
}
// end host check
}
else {
echo $statusCheck;
}
}
else {
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: *");
header("Content-Type: application/json");
echo json_encode(["error" => "Missing 'key' parameter"]);
}
?>