forked from purplepixie/phpdns
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dns.php
98 lines (80 loc) · 2.99 KB
/
dns.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
<?php // PHP DNS API CLI Example
/* -------------------------------------------------------------
This file is the PurplePixie PHP DNS Query Classes
The software is (C) Copyright 2008-2016 PurplePixie Systems
This is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
The software is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this software. If not, see www.gnu.org/licenses
For more information see www.purplepixie.org/phpdns
-------------------------------------------------------------- */
// Below is the recommended way to load PHP DNS, with individual
// classes:
use PurplePixie\PhpDns\DNSQuery;
require_once __DIR__ . '/src/PurplePixie/PhpDns/DNSAnswer.php';
require_once __DIR__ . '/src/PurplePixie/PhpDns/DNSQuery.php';
require_once __DIR__ . '/src/PurplePixie/PhpDns/DNSResult.php';
require_once __DIR__ . '/src/PurplePixie/PhpDns/DNSTypes.php';
// Here is the legacy way (single file to load classes) BUT must
// now also have the namespace line:
/*
require_once("dns.inc.php");
use PurplePixie\PhpDns\DNSQuery;
*/
$server="127.0.0.1";
$port=53;
$timeout=60;
$udp=true;
$debug=false;
$binarydebug=false;
$type="A";
$question="www.purplepixie.org";
if ($argc>1) {
for ($i=1; $i<$argc; $i++) {
$arg=$argv[$i];
if ($arg[0] == "@") {
$server = substr($arg, 1);
} elseif (($arg == "-t") || ($arg == "--t")) {
$i++;
$type = strtoupper($argv[$i]);
} elseif (($arg == "--tcp") || ($arg == "-tcp")) {
$udp = false;
} elseif (($arg == "--udp") || ($arg == "-udp")) {
$udp = true;
} elseif (($arg == "--debug") || ($arg == "-d")) {
$debug = true;
} elseif ($arg == "-dd") {
$debug = $binarydebug = true;
} else {
$question = $arg;
}
}
}
$query=new DNSQuery($server,$port,$timeout,$udp,$debug,$binarydebug);
echo "Querying: ".$question." -t ".$type." @".$server."\n";
$result=$query->query($question,$type);
if ($query->hasError()) {
echo "Query Error: " . $query->getLasterror() . "\n";
exit();
}
echo "Returned ".count($result)." Answers\n";
foreach ($result as $index => $record) {
echo $index . ". " . $record->getTypeid() . "(" . $record->getTypename() . ") => " . $record->getData() . " [";
echo $record->getString();
echo "]\n";
// additional data
if (count($record->getExtras()) > 0) {
foreach ($record->getExtras() as $key => $val) {
// We don't want to echo binary data
if ($key != 'ipbin') {
echo " - " . $key . " = " . $val . "\n";
}
}
}
}