async hostname detection
This commit is contained in:
parent
291c975662
commit
500851a0e9
34
src/hostname.php
Normal file
34
src/hostname.php
Normal file
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
header('Content-Type: application/json');
|
||||
|
||||
$ip = $_SERVER['REMOTE_ADDR'];
|
||||
if (substr($ip, 0, 9) === "10.23.42.") {
|
||||
$ip = "116.202.163.154";
|
||||
}
|
||||
|
||||
$ip = escapeshellcmd($ip);
|
||||
|
||||
print(json_encode(gethost($ip)));
|
||||
|
||||
function gethost($ip)
|
||||
{
|
||||
$ires = array();
|
||||
|
||||
$host = `host -s -W 1 $ip`;
|
||||
$host = ($host ? end( explode(' ', trim(trim($host), '.'))) : $ip);
|
||||
$ires = array();
|
||||
if(in_array($host, Array('reached', 'record', '3(NXDOMAIN)')))
|
||||
{
|
||||
$ires["status"] = "none";
|
||||
}
|
||||
else if (in_array( $host, Array('2(SERVFAIL)'))){
|
||||
$ires["status"] = "servfail";
|
||||
}
|
||||
else
|
||||
{
|
||||
$ires["status"] = "ok";
|
||||
$ires["response"] = $host;
|
||||
}
|
||||
|
||||
return $ires;
|
||||
}
|
|
@ -5,7 +5,7 @@
|
|||
<title>ip6.biz</title>
|
||||
<meta name="viewport" content="width=device-width" />
|
||||
<link rel="stylesheet" href="/css/bootstrap-dark.min.css" />
|
||||
<link rel="stylesheet" href="/css/connectivity.css?v=1" />
|
||||
<link rel="stylesheet" href="/css/connectivity.css?v=3" />
|
||||
</head>
|
||||
<body>
|
||||
<div class="navbar navbar-default navbar-fixed-top">
|
||||
|
@ -59,26 +59,26 @@
|
|||
<table id="v4_conn" class="table">
|
||||
<tr>
|
||||
<th>IPv4</th>
|
||||
<td class="proto_supported4"></td>
|
||||
<td class="proto_supported"></td>
|
||||
<td><span class="glyphicon glyphicon-question-sign" data-toggle="popover" data-trigger="hover" data-content="This test determines if you have IPv4 connectivity"></span></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Address</th>
|
||||
<td class="proto_address4"></td>
|
||||
<td class="proto_address"></td>
|
||||
<td>
|
||||
<span class="glyphicon glyphicon-question-sign" data-toggle="popover" data-trigger="hover" data-content="This is the address you are identified by on IPv4-only websites"></span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Hostname</th>
|
||||
<td class="proto_hostname4"></td>
|
||||
<td class="proto_hostname"></td>
|
||||
<td>
|
||||
<span class="glyphicon glyphicon-question-sign" data-toggle="popover" data-trigger="hover" data-content="This is the hostname you are identified by on IPv4-only websites"></span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>ISP</th>
|
||||
<td class="proto_isp4"></td>
|
||||
<td class="proto_isp"></td>
|
||||
<td><span class="glyphicon glyphicon-question-sign" data-toggle="popover" data-trigger="hover" data-content="This is the network provider that your IPv4 address belongs to"></span></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
@ -202,6 +202,6 @@
|
|||
</div>
|
||||
<script src="/js/vendor/jquery.min.js"></script>
|
||||
<script src="/js/vendor/bootstrap.min.js"></script>
|
||||
<script src="/js/connectivity.js?v=1"></script>
|
||||
<script src="/js/connectivity.js?v=3"></script>
|
||||
</body>
|
||||
</html>
|
|
@ -7,12 +7,8 @@ if (substr($ip, 0, 9) === "10.23.42.") {
|
|||
$ip = "116.202.163.154";
|
||||
}
|
||||
|
||||
$hostname = gethostbyaddr($ip);
|
||||
$res = array();
|
||||
$res["address"] = $ip;
|
||||
if ($ip !== $hostname){
|
||||
$res["hostname"] = $hostname;
|
||||
}
|
||||
$countrydb = '/var/lib/GeoIP/GeoLite2-Country.mmdb';
|
||||
$asndb = '/var/lib/GeoIP/GeoLite2-ASN.mmdb';
|
||||
|
||||
|
|
|
@ -2,20 +2,41 @@ var progress_bar = '<div class="progress progress-striped active"><div class="pr
|
|||
|
||||
function test_ipv4() {
|
||||
var $p = $("#v4_conn");
|
||||
$p.find(".proto_supported4").html(progress_bar).find(".progress-bar").css("width", "100%");
|
||||
$p.find(".proto_address4, .proto_hostname4, .proto_isp4").empty();
|
||||
$p.find(".proto_supported").html(progress_bar).find(".progress-bar").css("width", "100%");
|
||||
$p.find(".proto_address, .proto_hostname, .proto_isp").empty();
|
||||
$.ajax({
|
||||
url: "https://v4.ip6.biz/info.php",
|
||||
dataType: "json",
|
||||
timeout: 15000,
|
||||
success: function(resp) {
|
||||
$p.find(".proto_supported4").html("<span class='label label-success' style='font-size:1em'>Supported</span>");
|
||||
$p.find(".proto_address4").html("<span class='address'>" + resp.address + "</span>");
|
||||
$p.find(".proto_hostname4").html(resp.hostname ? resp.hostname : "<span class='label label-warning'>None</span>");
|
||||
$p.find(".proto_isp4").html("<img class='img-flag' src='/img/flags/" + resp.country + ".png' title='" + resp.country + "' />" + resp.asn);
|
||||
$p.find(".proto_supported").html("<span class='label label-success' style='font-size:1em'>Supported</span>");
|
||||
$p.find(".proto_address").html("<span class='address'>" + resp.address + "</span>");
|
||||
$p.find(".proto_isp").html("<img class='img-flag' src='/img/flags/" + resp.country + ".png' title='" + resp.country + "' />" + resp.asn);
|
||||
$p.find(".proto_hostname").html(progress_bar).find(".progress-bar").css("width", "100%");
|
||||
$.ajax({
|
||||
url: "https://v4.ip6.biz/hostname.php",
|
||||
dataType: "json",
|
||||
timeout: 2000,
|
||||
success: function(resp) {
|
||||
if (resp.status == "ok") {
|
||||
$p.find(".proto_hostname").html(resp.response);
|
||||
} else {
|
||||
if (resp.status == "servfail") {
|
||||
$p.find(".proto_hostname").html("<span class='label label-danger'>SERVFAIL</span>");
|
||||
} else if (resp.status == "none") {
|
||||
$p.find(".proto_hostname").html("<span class='label label-warning'>None</span>");
|
||||
} else {
|
||||
$p.find(".proto_hostname").html("<span class='label label-danger'>Test failed</span>");
|
||||
}
|
||||
}
|
||||
},
|
||||
error: function(xopt, err) {
|
||||
$p.find(".proto_supported4").html("<span class='label label-danger' style='font-size:1em'>Not supported</span>");
|
||||
$p.find(".proto_hostname").html("<span class='label label-danger'>Test failed</span>");
|
||||
},
|
||||
});
|
||||
},
|
||||
error: function(xopt, err) {
|
||||
$p.find(".proto_supported").html("<span class='label label-danger' style='font-size:1em'>Not supported</span>");
|
||||
},
|
||||
});
|
||||
}
|
||||
|
@ -31,15 +52,6 @@ function test_ipv6() {
|
|||
success: function(resp) {
|
||||
$p.find(".proto_supported").html("<span class='label label-success' style='font-size:1em'>Supported</span>");
|
||||
$p.find(".proto_address").html("<span class='address'>" + resp.address + "</span>");
|
||||
if (resp.hostname) {
|
||||
$p.find(".proto_hostname").html(resp.hostname);
|
||||
} else {
|
||||
if (resp.rdns_fail) {
|
||||
$p.find(".proto_hostname").html("<span class='label label-danger'>SERVFAIL</span>");
|
||||
} else {
|
||||
$p.find(".proto_hostname").html("<span class='label label-warning'>None</span>");
|
||||
}
|
||||
}
|
||||
$p.find(".proto_isp").html("<img class='img-flag' src='/img/flags/" + resp.country + ".png' title='" + resp.country + "' />" + resp.asn);
|
||||
$p.find(".proto_icmp").html(progress_bar).find(".progress-bar").css("width", "100%");
|
||||
$.ajax({
|
||||
|
@ -57,6 +69,28 @@ function test_ipv6() {
|
|||
$p.find(".proto_icmp").html("<span class='label label-default'>Not tested</span>");
|
||||
},
|
||||
});
|
||||
$p.find(".proto_hostname").html(progress_bar).find(".progress-bar").css("width", "100%");
|
||||
$.ajax({
|
||||
url: "https://v6.ip6.biz/hostname.php",
|
||||
dataType: "json",
|
||||
timeout: 2000,
|
||||
success: function(resp) {
|
||||
if (resp.status == "ok") {
|
||||
$p.find(".proto_hostname").html(resp.response);
|
||||
} else {
|
||||
if (resp.status == "servfail") {
|
||||
$p.find(".proto_hostname").html("<span class='label label-danger'>SERVFAIL</span>");
|
||||
} else if (resp.status == "none") {
|
||||
$p.find(".proto_hostname").html("<span class='label label-warning'>None</span>");
|
||||
} else {
|
||||
$p.find(".proto_hostname").html("<span class='label label-danger'>Test failed</span>");
|
||||
}
|
||||
}
|
||||
},
|
||||
error: function(xopt, err) {
|
||||
$p.find(".proto_hostname").html("<span class='label label-danger'>Test failed</span>");
|
||||
},
|
||||
});
|
||||
},
|
||||
error: function(xopt, err) {
|
||||
$p.find(".proto_supported").html("<span class='label label-danger' style='font-size:1em'>Not supported</span>");
|
||||
|
|
Loading…
Reference in a new issue