tungd / elixir-dns

DNS library for Elixir
BSD 3-Clause "New" or "Revised" License
114 stars 37 forks source link

Can't run a simple DNS.resolve #2

Closed kedare closed 7 years ago

kedare commented 7 years ago

Hello,

I tried to use the library but I can't get a simple DNS.resolve to work correctly, is the README up to date ?

Here is what I get :

iex(3)> DNS.resolve("google.com")
** (MatchError) no match of right hand side value: []
    (dns) lib/dns.ex:10: DNS.resolve/2

Using {:dns, "~> 0.0.3"}

Thank you.

tungd commented 7 years ago

Hi @kedare,

I still can't find the cause of this issue. Per my testing the error is because there's no answer for the query "google.com" (which is weird).

odarriba commented 7 years ago

A better response for not founds is handled at #8 .

However, there is some strange behaviour on the query method. Checking responses with dig command and the same nameserver, I see several differences within the results 🤔

tungd commented 7 years ago

@odarriba : Do you have any example response?

odarriba commented 7 years ago
; <<>> DiG 9.11.1-P1 <<>> @8.8.8.8 icann.org
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 18324
;; flags: qr rd ra ad; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 512
;; QUESTION SECTION:
;icann.org.         IN  A

;; ANSWER SECTION:
icann.org.      350 IN  A   192.0.43.7

;; Query time: 34 msec
;; SERVER: 8.8.8.8#53(8.8.8.8)
;; WHEN: Mon Jul 10 10:23:10 CEST 2017
;; MSG SIZE  rcvd: 54
iex(1)> DNS.query("icann.org", {"8.8.8.8", 53})
%DNS.Record{anlist: [], arlist: [],
 header: %DNS.Header{aa: false, id: 0, opcode: :query, pr: false, qr: true,
  ra: true, rcode: 2, rd: false, tc: false}, nslist: [],
 qdlist: [%DNS.Query{class: :in, domain: 'icann.org', type: :a}]}
odarriba commented 7 years ago

We need to set the :rd flag to true in order to allow recursive discovery 🤔