Skip to content

Instantly share code, notes, and snippets.

@bsetmet bsetmet/info.php
Created Sep 13, 2018

Embed
What would you like to do?
PHP Example to display 'this' server's external IP Address and the corresponiding DNS Record
<?php /*
"The MIT License"
Copyright 2018 Jeremy D. Gerdes
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ include_once "assets/time.php";?>
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script charset="utf-8" src="assets/auto_reload.js"></script>
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="stylesheet" href="/assets/global_style.css">
<script>
/* Requires 'assets/auto_reload.js'
Reload page using the method found here: https://stackoverflow.com/questions/2787679/how-to-reload-page-every-5-second
but should move to this answer's method that recomends not using setInterval (for entire page, or just sections),
as current method can cause the page to never finish loading prior to calling another reload:https://stackoverflow.com/a/5052661/3842368
*/
$(document).ready(function() {
setInterval(function() {
reload_page()
}, 3000);
});
</script>
</head>
<body>
<h1>Bsetmet.com IP Address</h1>
<table class="tg">
<tr>
<th>Source</th>
<th>Address</th>
<th>Time</th>
<th>microseconds for IP Lookup</th>
</tr>
<?php
//Build table from array of data...
//Removed "https://wtfismyip.com/text", it appears to fail when sent from http:// instead of https://
//Removed "http://canihazip.com/s", this routinely takes 600+ milliseconds
$arrIpSource = array("http://myip.dnsdynamic.com/","http://checkip.amazonaws.com/","https://ipinfo.io/ip"); //"http://ifconfig.me/ip" takes a looooong time to respond
foreach($arrIpSource as $ipSource) {
$dblStartIpLookup = microtime(true);
$ip = file_get_contents($ipSource);
echo "<tr>";
echo "<td>$ipSource</td>";
echo "<td>$ip</td>";
echo "<td>".GetDateTimeFormat(time())."</td>";
echo "<td>".(1000*(microtime(true)-$dblStartIpLookup))."</td>";
echo "</tr>";
}
?>
</table>
<?php
echo "<h1> Current DNS propogation for bsetmet.com</h1>";
echo "<div>";
$dblStartDnsResults = microtime(true);
echo GetDnsResultTableRows(dns_get_record("www.bsetmet.com",DNS_ANY),true,false);
$strDnsTimes ="<div>DNS Looup for www.bsetmet.com took ".(1000*(microtime(true)-$dblStartDnsResults))." microseconds </div>";
$dblStartDnsResults = microtime(true);
echo GetDnsResultTableRows(dns_get_record("bsetmet.com", DNS_ANY),false,true);
$strDnsTimes = $strDnsTimes."<div>DNS Looup for bsetmet.com took ".(1000*(microtime(true)-$dblStartDnsResults))." microseconds </div>";
$dblStartDnsResults = microtime(true);
echo $strDnsTimes;
function GetDnsResultTableRows($results,$fIncludeTableHeaders=false,$fCloseTable=false){
if($fIncludeTableHeaders){
echo "<p><a href='http://www.php.net/manual/en/function.dns-get-record.php'>Column Header Details</a></p>";
echo "<table class='tg'>";
echo "<th>host</th>";
echo "<th>ttl</th>";
echo "<th>type</th>";
echo "<th>ip</th>";
echo "<th>target</th>";
echo "<th>class</th>";
echo "<th>mname</th>";
echo "<th>rname</th>";
echo "<th>serial</th>";
echo "<th>refresh</th>";
echo "<th>retry</th>";
echo "<th>expire</th>";
echo "<th>minimum-ttl</th>";
}
foreach($results as $dns_return) {
echo "<tr>";
echo "<td>".$dns_return['host']."</td>";
echo "<td>".$dns_return['ttl']."</td>";
echo "<td>".$dns_return['type']."</td>";
echo "<td>".$dns_return['ip']."</td>";
echo "<td>".$dns_return['target']."</td>";
echo "<td>".$dns_return['class']."</td>";
echo "<td>".$dns_return['mname']."</td>";
echo "<td>".$dns_return['rname']."</td>";
echo "<td>".$dns_return['serial']."</td>";
echo "<td>".$dns_return['refresh']."</td>";
echo "<td>".$dns_return['retry']."</td>";
echo "<td>".$dns_return['expire']."</td>";
echo "<td>".$dns_return['minimum-ttl']."</td>";
echo "</tr>";
}
if($fCloseTable){
echo "</table>";
}
}
?>
<br/>
<div class=informational>
<?php
$dblTotalRunTime =(microtime(true)-$_SERVER["REQUEST_TIME_FLOAT"]);
echo "This page refreshes roughly every ".round(3+$dblTotalRunTime,3)." seconds, ".round($dblTotalRunTime,3)." of which is server side scripting.";
?>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.