Posted to tcl by colin at Wed Aug 01 23:10:51 GMT 2012view raw

  1. # Terry Dawson's "very educated guess" algorithm:
  2. #
  3. # You can reasonably assume that the 'local' DNS server is (one of)
  4. # the DNS server(s) serving the local domain.
  5. #
  6. # So iff the local hostname is set correctly you could use:
  7. # gethostname(), identify the domain component,
  8. # and then undertake a DNS request for NS records for that domain.
  9. #
  10. # That should provide you with a list of usable 'local' DNS servers."
  11. # It won't help you find topologically local DNS proxies for example,
  12. # but it will help you find usable DNS servers.
  13.  
  14. package require dns
  15. #package require udp
  16.  
  17. proc doit {addr {server localhost}} {
  18. set token [::dns::resolve $addr]
  19. if {[::dns::wait $token] eq "ok"} {
  20. puts [::dns::result $token]
  21. } else {
  22. puts [::dns::error $token]
  23. }
  24. ::dns::cleanup $token
  25. }
  26.  
  27. proc findDNS {} {
  28. set host [info hostname]
  29. }
  30.  
  31. doit [lindex $argv 0]