Skip to content

Instantly share code, notes, and snippets.

/dns.php
Created Aug 31, 2017

Embed
What would you like to do?
DNS Lookup - Modified
<?php
$result = array();
$result_html = '';
if (isset($_GET['domain']) && !empty($_GET['domain'])) {
$domain_regex = '/[a-z\d][a-z\-\d\.]+[a-z\d]/i';
if (preg_match($domain_regex, $_GET['domain'])) {
if ($url = parse_url($_GET['domain'])) { //compatible when user post an url instead of a domain
if (isset($url['host'])) {
$result = dns_get_record($url['host'], DNS_A + DNS_AAAA + DNS_CNAME);
} else if (isset($url['path'])) {
$result = dns_get_record($url['path'], DNS_A + DNS_AAAA + DNS_CNAME);
}
}
}
if (empty($result)) {
$result_html = 'Nothing found or Domain Invalid';
} else {
foreach($result as $r) {
reset($r);
$host = current($r);
$type = next($r);
$value = next($r);
$result_html .= sprintf("<tr><td>%s</td><td>%s</td><td>%s</td></tr>\n", $host, $type, $value);
}
$result_html = "<hr>\n<table>\n$result_html</table>\n";
}
}
?><!DOCTYPE HTML>
<html xmlns="http://www.w3.org/1999/html">
<head>
<meta charset="UTF-8"/>
<title>Raw Dns Lookup</title>
<style>/* somethin from bootstrap */
button,input {margin: 0;font-size: 100%;vertical-align: middle;}
hr {margin: 20px 0;border: 0;border-top: 1px solid #eeeeee;border-bottom: 1px solid #ffffff;}
label {margin-bottom: 3px;}
.form-inline {vertical-align: middle;}
table {width: 100%;text-align: center;margin: auto;}
</style>
</head>
<body>
<div style="text-align: center;width: 800px;margin: 1em auto">
<h1>Raw Dns Lookup</h1>
<?=$result_html?$result_html:''?>
<hr/>
<p>Server Location:
<?
$geo = json_decode(file_get_contents('http://smart-ip.net/geoip-json'));
echo $geo->countryName;
?>
<br/>
<span>Powered by <a href="http://weibo.com/horsley" title="Developer:horsley" target="_blank">Horsley</a></span>
</p>
</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.