Skip to content

Instantly share code, notes, and snippets.

@himajin315
Created January 31, 2014 15:06
Show Gist options
  • Save himajin315/8733744 to your computer and use it in GitHub Desktop.
Save himajin315/8733744 to your computer and use it in GitHub Desktop.
Net_DNS2を使ったサンプルコード
<!DOCTYPE html>
<head>
<title>sample (Net_DNS2)</title>
<meta charset="UTF-8">
</head>
<body>
<div class="contents">
<h1>sample (Net_DNS2)</h1>
<form action="sample_net_dns2.php" method="get">
ホスト名: <input type="text" name="host" value="<?php if(isset($_GET['host'])) echo $_GET['host']; ?>">
<select name="record">
<option>A</option>
<option>AAAA</option>
<option>ANY</option>
<option>CAA</option>
<option>CNAME</option>
<option>DLV</option>
<option>MX</option>
<option>NS</option>-->
<option>SPF</option>-->
<option>TXT</option>-->
</select>
<input type="submit" value="送信">
</form>
<?php
if(isset($_GET['host'])&&isset($_GET['record'])){
$host = $_GET['host'];
$type = $_GET['record'];
echo "<h2>ホスト名:".$host." Record:".$type."</h2>";
}
if(isset($host)&&isset($type)){
$ns = array('8.8.8.8', '8.8.4.4');
require_once 'Net/DNS2.php';
$rs = new Net_DNS2_Resolver(array('nameservers' => $ns));
} else {
die("No host specified.");
}
try {
$result = $rs->query($host, $type);
} catch(InvalidArgumentException $e) {
echo "Failed to query: " . $e->getMessage() . "\n";
}
// print output
echo "<h2>Ansesr</h2>";
print("<pre>");
print_r($result->answer);
print("</pre>");
echo "<h2>ALL</h2>";
print("<pre>");
print_r($result);
print("</pre>");
?>
<h3><a href="index.html">戻る</a></h2>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment