cl-rw

Layered streams for Common Lisp
git clone https://logand.com/git/cl-rw.git/
Log | Files | Refs

commit 5432d0eadf88294c7b8ef3fff665c82cbc47fe3d
parent b9f176ce3b6708af2ebd3c9a9b8ed65ef51d2918
Author: Tomas Hlavaty <tom@logand.com>
Date:   Sat, 27 Dec 2014 02:39:55 +0100

default-server, preconfigured servers and automatic ptr detection

Diffstat:
Mdns.lisp | 145++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------
1 file changed, 96 insertions(+), 49 deletions(-)

diff --git a/dns.lisp b/dns.lisp @@ -399,19 +399,45 @@ (ldb (byte 4 12) e))) (write-string "ip6.arpa" s))))) -(defun query (name server &key (type 'A) (class 'IN) (port 53)) - (clrhash *cache*) ;; TODO remove - (let ((i 0) - (name (etypecase name - (string name) - (rw.socket:ipv4-address - (assert (eq 'PTR type)) - (assert (eq 'IN class)) - (reverse-query-name name)) - (rw.socket:ipv6-address - (assert (eq 'PTR type)) - (assert (eq 'IN class)) - (reverse-query-name name))))) +(defparameter *default-server* :google) + +(defparameter *servers* + `((:opennic ;; http://www.opennicproject.org/ (.bit domains) + ,(rw.socket:make-ipv4-address "192.121.170.170") + ,(rw.socket:make-ipv4-address "179.43.143.69")) + (:opennic-us + ,(rw.socket:make-ipv4-address "107.170.95.180") + ,(rw.socket:make-ipv4-address "75.127.14.107")) + (:opendns + ,(rw.socket:make-ipv4-address "208.67.222.222") ;; resolver1.opendns.com + ,(rw.socket:make-ipv4-address "208.67.220.220") ;; resolver2.opendns.com + ,(rw.socket:make-ipv4-address "208.67.222.220") + ,(rw.socket:make-ipv4-address "208.67.220.222") + ,(rw.socket:make-ipv4-address "2620:0:ccc::2") ;;;;; + ,(rw.socket:make-ipv4-address "2620:0:ccd::2")) ;;;;; + (:google + ,(rw.socket:make-ipv4-address "8.8.8.8") + ,(rw.socket:make-ipv4-address "8.8.4.4") + ,(rw.socket:make-ipv4-address "2001:4860:4860::8888") ;;;; + ,(rw.socket:make-ipv4-address "2001:4860:4860::8844")) + (:comodo + ,(rw.socket:make-ipv4-address "8.26.56.26") + ,(rw.socket:make-ipv4-address "8.20.247.20")) + (:yandex-basic + ,(rw.socket:make-ipv4-address "77.88.8.8") + ,(rw.socket:make-ipv4-address "77.88.8.1")) + (:yandex-safe + ,(rw.socket:make-ipv4-address "77.88.8.88") + ,(rw.socket:make-ipv4-address "77.88.8.2")) + (:yandex-family + ,(rw.socket:make-ipv4-address "77.88.8.7") + ,(rw.socket:make-ipv4-address "77.88.8.3")))) + +(defun query (name &key (server *default-server*) type (class 'IN) (port 53)) + ;;(clrhash *cache*) + ;;(mapc 'remember (parse-named.root "/home/tomas/git/cl-rw/named.root")) + ;;(mapc 'remember (parse-root.zone "/home/tomas/git/cl-rw/root.zone")) + (let ((i 0)) (labels ((rec (name type server) (or (lookup name type class) @@ -438,42 +464,63 @@ (when z (return-from rec z))))) (SOA (return-from rec nil)))))))))) - (values (rec name type server) i)))) - -;;(query "logand.com" (rw.socket:make-ipv4-address "8.8.8.8") :type 'MX) -;;(query "mx1.logand.com" (rw.socket:make-ipv4-address "8.8.8.8") :type 'A) -;;(query "mx1.logand.com" (rw.socket:make-ipv4-address "8.8.8.8") :type 'CNAME) -;;(query "logand.com" (rw.socket:make-ipv4-address "8.8.8.8") :type 'SOA) -;;(query "google.com" (rw.socket:make-ipv4-address "8.8.8.8") :type 'AAAA) -;;(query "google.com" (rw.socket:make-ipv4-address "8.8.8.8") :type 'A) -;;(query "google.com" (rw.socket:make-ipv4-address "8.8.8.8") :type 'MX) -;;(query "google.com" (rw.socket:make-ipv4-address "8.8.8.8") :type 'NS) -;;(query "google.com" (rw.socket:make-ipv4-address "8.8.8.8") :type 'SOA) -;;(query "google.com" (rw.socket:make-ipv4-address "8.8.8.8") :type 'TXT) -;;(query "google.com" (rw.socket:make-ipv4-address "8.8.8.8") :type 'CNAME) -;;(query "mx1.logand.com" (rw.socket:make-ipv4-address "8.8.8.8") :type 'AAAA) -;;(query "google.com" (rw.socket:make-ipv4-address "8.8.8.8") :type 'TXT) -;;(query "google.com" (rw.socket:make-ipv4-address "198.41.0.4") :type 'A) -;;(query "mx1.logand.com" (rw.socket:make-ipv4-address "198.41.0.4") :type 'A) -;;(query "google.com" (rw.socket:make-ipv4-address "8.8.8.8") :type 'RRSIG) -;;(query "google.com" (rw.socket:make-ipv4-address "8.8.8.8") :type 'DS) -;;(query "8.8.8.8.in-addr.arpa." (rw.socket:make-ipv4-address "8.8.8.8") :type 'PTR) -;;(query "8.8.8.8.in-addr.arpa" (rw.socket:make-ipv4-address "8.8.8.8") :type 'PTR) -;;(query ".ip6.arpa" (rw.socket:make-ipv4-address "8.8.8.8") :type 'PTR) -;;(query "8.70.192.82.in-addr.arpa" (rw.socket:make-ipv4-address "8.8.8.8") :type 'PTR) -;;(query (rw.socket:make-ipv4-address "82.192.70.8") (rw.socket:make-ipv4-address "8.8.8.8") :type 'PTR) -;;(query (rw.socket:make-ipv6-address #(10752 5200 16392 2049 0 0 0 4110)) (rw.socket:make-ipv4-address "8.8.8.8") :type 'PTR) -;;(query "ber01s09-in-x0e.1e100.net" (rw.socket:make-ipv4-address "8.8.8.8") :type 'AAAA) -;;(query "google.com" (rw.socket:make-ipv4-address "8.8.8.8") :type 'AAAA) -;;(query (rw.socket:make-ipv4-address "94.242.206.239") (rw.socket:make-ipv4-address "8.8.8.8") :type 'PTR) -;;(query (rw.socket:make-ipv4-address "107.191.45.22") (rw.socket:make-ipv4-address "8.8.8.8") :type 'PTR) -;;(query "cr.yp.to" (rw.socket:make-ipv4-address "8.8.8.8") :type 'A) -;;(query "cr.yp.to" (rw.socket:make-ipv4-address "8.8.8.8") :type 'MX) -;;(query "yp.to" (rw.socket:make-ipv4-address "8.8.8.8") :type 'NS) -;;(query "cr.yp.to" (rw.socket:make-ipv4-address "208.67.222.222") :type 'A) - -;;(query "google.com" (rw.socket:make-ipv4-address "8.8.8.8") :type 'ANY) -;;(query "logand.com" (rw.socket:make-ipv4-address "8.8.8.8") :type 'ANY) + (values + (rec (etypecase name + (string name) + (rw.socket:ipv4-address + (assert (eq 'PTR type)) + (assert (eq 'IN class)) + (reverse-query-name name)) + (rw.socket:ipv6-address + (assert (eq 'PTR type)) + (assert (eq 'IN class)) + (reverse-query-name name))) + (or type + (etypecase name + (string 'A) + (rw.socket:ipv4-address 'PTR) + (rw.socket:ipv6-address 'PTR))) + (etypecase server + (symbol (cadr (assoc server *servers*))) + (rw.socket:ipv4-address server) + (rw.socket:ipv6-address server))) + i)))) + +;;(query "logand.com" :type 'MX) +;;(query "mx1.logand.com") +;;(query "mx1.logand.com" :type 'CNAME) +;;(query "logand.com" :type 'SOA) +;;(query "google.com" :type 'AAAA) +;;(query "google.com") +;;(query "google.com" :type 'MX) +;;(query "google.com" :type 'NS) +;;(query "google.com" :type 'SOA) +;;(query "google.com" :type 'TXT) +;;(query "google.com" :type 'CNAME) +;;(query "mx1.logand.com" :type 'AAAA) +;;(query "google.com" :type 'TXT) +;;(query "google.com" :server (rw.socket:make-ipv4-address "198.41.0.4")) +;;(query "mx1.logand.com" :server (rw.socket:make-ipv4-address "198.41.0.4")) ;;;;;;;;;;;;; 7x +;;(query "google.com" :type 'RRSIG) +;;(query "google.com" :type 'DS) +;;(query "8.8.8.8.in-addr.arpa." :type 'PTR) +;;(query "8.8.8.8.in-addr.arpa" :type 'PTR) +;;(query ".ip6.arpa" :type 'PTR) +;;(query "8.70.192.82.in-addr.arpa" :type 'PTR) +;;(query (rw.socket:make-ipv4-address "82.192.70.8")) +;;(query (rw.socket:make-ipv6-address #(10752 5200 16392 2049 0 0 0 4110))) +;;(query "ber01s09-in-x0e.1e100.net" :type 'AAAA) +;;(query "google.com" :type 'AAAA) +;;(query (rw.socket:make-ipv4-address "94.242.206.239")) +;;(query (rw.socket:make-ipv4-address "107.191.45.22")) +;;(query "cr.yp.to") +;;(query "cr.yp.to" :type 'MX) +;;(query "yp.to" :type 'NS) +;;(query "cr.yp.to" :server (rw.socket:make-ipv4-address "208.67.222.222")) +;;(query "c64games.bit" :server :opennic) + +;;(query "google.com" :type 'ANY) +;;(query "logand.com" :type 'ANY) ;;http://technet.microsoft.com/en-us/library/cc758353(v=ws.10).aspx (defun parse-named.root-line (line)