Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Simple PHP code act as a dig tool to find dns records
<?php
$result = array();
$result_html = '';
if (isset($_POST['domain']) && !empty($_POST['domain'])) {
$domain_regex = '/[a-z\d][a-z\-\d\.]+[a-z\d]/i';
if (preg_match($domain_regex, $_POST['domain'])) {
if ($url = parse_url($_POST['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 = '<hr>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>
<form method="post">
<div class="form-inline">
<label for="domain">Domain: </label>
<input id="domain" type="text" name="domain" value="<?=empty($_POST['domain'])?'':$_POST['domain']?>">
<button type="submit">Dig</button>
</div>
</form>
<?=$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>
@aniljalela

This comment has been minimized.

Copy link

aniljalela commented Jun 30, 2014

$geo = json_decode(file_get_contents('http://smart-ip.net/geoip-json')); not working

@Iremar

This comment has been minimized.

Copy link

Iremar commented Jun 13, 2015

replace lines 58 and 59 for these

$geo = json_decode(file_get_contents("http://freegeoip.net/json/".$_POST['domain']));
echo $geo->country_name;

@biswajeetparida

This comment has been minimized.

Copy link

biswajeetparida commented May 2, 2016

only returns single record for CNAME. Multiple Record are filter

@maheshsharma1991

This comment has been minimized.

Copy link

maheshsharma1991 commented Aug 22, 2018

replace lines 58 and 59 for these

$geo = json_decode(file_get_contents("http://freegeoip.net/json/".$_POST['domain']));
echo $geo->country_name;

this script does not help in found the records of domain

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.