-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnet_dns2.php
115 lines (105 loc) · 3.95 KB
/
net_dns2.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<!DOCTYPE html>
<head>
<title>DNS GET RECORD (Net_DNS2)</title>
<meta charset="UTF-8">
<link href="./style.css" rel="stylesheet" type="text/css">
</head>
<body>
<div class="contents">
<h1>DNS GET RECORD (Net_DNS2)</h1>
<form action="net_dns2.php" method="get">
ホスト名: <input type="text" name="host" value="<?php if(isset($_GET['host'])) echo $_GET['host']; ?>">
<input type="submit" value="送信">
</form>
<?php
if(isset($_GET['host'])){
$host = $_GET['host'];
echo "<h2>ホスト名:".$host."</h2>";
}
if(isset($host)){
$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_any = $rs->query($host, 'ANY');
$result_mx = $rs->query($host, 'MX');
$result_ns = $rs->query($host, 'NS');
} catch(Exception $e) {
echo "見つかりませんでした。";
}
if(isset($result_any->answer)){
echo '<table>';
//各レコードを表示させる
foreach ($result_any->answer as $record_info){
if($record_info->type == "SOA"){
echo '<tr><td colspan=2 class="r-type">SOA records - Source Of Authority</td>';
echo '<tr><td>'.$record_info->name.'. serial number </td><td>'.$record_info->serial.'</td></tr>';
echo '<tr><td>'.$record_info->name.'. MNAME </td><td>'.$record_info->mname.'</td></tr>';
echo '<tr><td>'.$record_info->name.'. RNAME </td><td>'.$record_info->rname.'</td></tr>';
echo '<tr><td>'.$record_info->name.'. REFRESH </td><td>'.$record_info->refresh.'</td></tr>';
echo '<tr><td>'.$record_info->name.'. RETRY </td><td>'.$record_info->retry.'</td></tr>';
echo '<tr><td>'.$record_info->name.'. TTL </td><td>'.$record_info->ttl.'</td></tr>';
}
if($record_info->type == "TXT"){
echo '<tr><td colspan=2 class="r-type">TXT records</td>';
echo '<tr><td>'.$record_info->name.'. TXT </td><td>';
if($record_info->text){
foreach ($record_info->text as $record_txt_info){
echo $record_txt_info.'</td></tr>';
}
}
}
if($record_info->type == "A"){
echo '<tr><td colspan=2 class="r-type">A records</td>';
echo '<tr><td>'.$record_info->name.'. A </td><td>'.$record_info->address.'</td></tr>';
}
if($record_info->type == "AAAA"){
echo '<tr><td colspan=2 class="r-type">AAAA records</td>';
echo '<tr><td>'.$record_info->name.'. AAAA </td><td>'.$record_info->address.'</td></tr>';
}
}
if($result_mx->answer){
echo '<tr><td colspan=2 class="r-type">MX records - Mailservers</td></tr>';
foreach ($result_mx->answer as $record_mx_info){
$mx_host = strtolower($record_mx_info->exchange);
try {
$result_a = $rs->query($mx_host, 'A');
echo '<tr><td>'.$record_mx_info->exchange.'</td><td>'.$result_a->answer[0]->address.'</td></tr>';
} catch(Exception $e) {
echo '<tr style="color:red;"><td>'.$record_mx_info->exchange.'</td><td>NXDOMAIN</td></tr>';
}
try {
$result_aaaa = $rs->query($mx_host, 'AAAA');
if(isset($result_aaaa->answer[0]->address)){
echo '<tr><td>'.$record_mx_info->exchange.' AAAA </td><td>'.$result_aaaa->answer[0]->address.'</td></tr>';
}
} catch(Exception $e) {
}
}
}
//NSレコードがあるならば表示させる
if($result_ns->answer){
echo '<tr><td colspan=2 class="r-type">NS records - Nameservers</td>';
foreach ($result_ns->answer as $record_ns_info){
$ns_host = strtolower($record_ns_info->nsdname);
$result_ns = $rs->query($ns_host, 'A');
echo '<tr><td>'.$record_ns_info->nsdname.'</td><td>'.$result_ns->answer[0]->address.'</td></tr>';
try {
$result_aaaa = $rs->query($ns_host, 'AAAA');
if(isset($result_aaaa->answer[0]->address)){
echo '<tr><td>'.$record_ns_info->nsdname.' AAAA </td><td>'.$result_aaaa->answer[0]->address.'</td></tr>';
}
} catch(Exception $e) {
}
}
}
echo "</table>";
}
?>
<h3><a href="index.html">戻る</a></h2>
</div>
</body>
</html>