|
|
ns_queryresolve type ?nameserver? domainname
ns_queryresolve implements a subset of the nslookup program functions. You can query a nameserver about the specified domainname for records of any of the following types: a, cname, ns, soa, mx, or host. If there isn't a record for the particular type, the ns_set size will be 0 along with no fields.
The a type is for address lookups, and it will will return all of the addresses for a particular host. For the cname type, if the query comes back "null" from DNS, it returns a set with null fields. The ns, soa, and mx types require an authoritative domain/host or the command returns a set with no fields.
If no nameserver is specified, the first nameserver in the host's resolv.conf is used.
##----- Example registered Tcl proc -----#
ns_register_proc GET /nslookup ns_lookup
proc ns_lookup {conn ignored} {
set type {"a" "cname" "ns" "mx" "soa" "host" "host" }
set domain {"aol.com" "www.aol.com" "aol.com" "aol.com"
"aol.com" "aol.com" "152.163.214.10" }
set returnstring ""
set nameserver ""
for { set a 0 } {$a < [llength $type]} {incr a} {
set nsset [ns_queryresolve [lindex $type $a] $nameserver
[lindex $domain $a] ]
append returnstring "Type: [lindex $type $a]\n"
set size [ns_set size $nsset]
append returnstring "Ns_Set size : $size\n"
for {set i 0} {$i < [ns_set size $nsset]} {incr i} {
set key [ns_set key $nsset $i]
set value [ns_set value $nsset $i]
append returnstring "$key : $value\n"
}
append returnstring "---------------------------------\n"
ns_set free $nsset
}
ns_return $conn 200 text/plain $returnstring
}