Added fetch IPv4 & IPv6 from domain dns api

Added fetch IPv4 & IPv6 from domain dns api
This commit is contained in:
cp6 2021-01-27 10:27:46 +11:00
parent f53b2bb479
commit e5c836629b
3 changed files with 43 additions and 0 deletions

View File

@ -265,6 +265,35 @@ $(document).on("click", "#addDomainBTN", function () {
$("#addSharedHosting").removeClass("show");
});
$(document).on("click", "#fillIpv4", function () {
var host_name = $('#hostname').val();
if (host_name) {
$.ajax({
type: "GET",
url: "get_ip.php",
data: {"type" : "dns_search", "hostname": host_name, "type": "A"},
success: function (result) {
$('#ipv4').val(result);
}
});
//Now wait 3 seconds before checking AAAA
setTimeout(function(){
$.ajax({
type: "GET",
url: "get_ip.php",
data: {"type" : "dns_search", "hostname": host_name, "type": "AAAA"},
success: function (result) {
if (result != ''){
$('#ipv6').val(result);
} else {
$('#ipv6').val('');
}
}
});
}, 3000);
}
});
function modalServerEdit(id) {
$.ajax({
type: "GET",

View File

@ -36,6 +36,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
} elseif ($_GET['value'] == 'domain') {
$idle->viewMoreDomainModal($_GET['id']);//View more details modal
}
} elseif ($_GET['type'] == 'dns_search') {
$idle->getIpForDomain($_GET['hostname'], $_GET['type']);
}
}
} elseif ($_SERVER['REQUEST_METHOD'] === 'POST') {

View File

@ -1666,6 +1666,7 @@ class idlers extends helperFunctions
$this->tagOpen('div', 'input-group');
$this->inputPrepend('Hostname');
$this->textInput('hostname', '', 'form-control', true, 1, 124);
$this->outputString('<div class="input-group-append"><span class="input-group-text"><a id="fillIpv4" href="#"><i class="fas fa-search"></i></a></span></div>');
$this->tagClose('div', 2);
$this->colOpen('col-12 col-md-4');
$this->tagOpen('div', 'input-group');
@ -2787,6 +2788,17 @@ class idlers extends helperFunctions
$this->tagClose('div', 2);
}
public function getIpForDomain(string $domain, string $type = 'A'): string
{//Gets IP from A record for a domain
$data = json_decode(file_get_contents("https://whatsmydns.net/api/details?server=428&type=$type&query=$domain"), true);
if (isset($data['data'][0]['response'][0])) {
if (strlen($data['data'][0]['response'][0]) > 6) {
return $data['data'][0]['response'][0];
}
}
return "";//Doesnt exist/null/empty/invalid
}
}
class itemInsert extends idlers