darnahsan

darnahsan

DNS wireformat support in Elixir?

Are there any libs to work with DNS wire format ? I found this lib for erlang not sure how to work with this though

anyone experienced with the format got some questions, working on a side project

I have this code where I can read the incoming application/dns-message body of the request

echo -n 'q80BAAABAAAAAAAAA3d3dwdleGFtcGxlA2NvbQAAAQAB' | base64 | curl -H 'content-type: application/dns-message' --data-binary @- https://cloudflare-dns.com/dns-query -o -

 post "/" do
    {:ok, body, conn} = Plug.Conn.read_body(conn)

    {:ok, query} = String.trim(body) |> Base.url_decode64(padding: false)

    IO.inspect(query, label: "Query")

    conn
    |> put_resp_content_type("application/dns-message")
    |> send_resp(
      200,
      Jason.encode!(%{
        msg: "I don't have a heart but I am alive!"
      })
    )
  end

i am trying to work this out https://developers.cloudflare.com/1.1.1.1/dns-over-https/wireformat

Not sure how to make a request to the upstream DNS from wireformat and return a response I am using GitHub - tungd/elixir-dns: DNS library for Elixir to do the JSON format. Need to know how to get the wireformat to standard domain to send using elixir-dns and then convert the response back to wireformat

Marked As Solved

evadne

evadne

Just a thought but try inet_dns:decode/1 in Erlang as per otp/inet_dns.erl at master · erlang/otp · GitHub and maybe other functions in that module will help you as well.

If it works, you will have the benefit of not having to pull an extra dependency

According to the RFC RFC 8484 - DNS Queries over HTTPS (DoH) the message is formatted as per RFC 1035 which should be what inet_dns:decode/1 accepts

Also Liked

darnahsan

darnahsan

after lack of my erlang understanding I decided to dig into tungd/elixir-dns code out of curiosity to see how it was handling things and it is doing what @evadne suggested and has some nice wrapper around erlang code which i ended up using. elixir-dns/record.ex at master · tungd/elixir-dns · GitHub

Big thanks to the elixir community for being supportive and having a solution to almost everything :grin:

darnahsan

darnahsan

Thanks @evadne passed the 1st hurdle , will upate the thread with progress for others if they ever need this info. might ping here if I hit a roadblock :sweat_smile:

post "/" do
    {:ok, body, conn} = Plug.Conn.read_body(conn)

    IO.inspect(body, label: "body")
    :inet_dns.decode(body) |> IO.inspect(label: "inet_dns.decode")
    conn
    |> put_resp_content_type("application/dns-message")
    |> send_resp(
      200,
      Jason.encode!(%{
        msg: "I don't have a heart but I am alive!"
      })
    )
  end
body: <<171, 205, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 3, 119, 119, 119, 7, 101, 120, 97, 
  109, 112, 108, 101, 3, 99, 111, 109, 0, 0, 1, 0, 1>>
inet_dns.decode: {:ok,
 {:dns_rec,
  {:dns_header, 43981, false, :query, false, false, true, false, false, 0},
  [{:dns_query, 'www.example.com', :a, :in}], [], [], []}}
bortzmeyer

bortzmeyer

Just for information, my DNS server written in Elixir uses (currently) the elixir-dns library. Because it does not seem actually maintained, I had to fork. My code may give you ideas.

Where Next?

Popular in Questions Top

Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
LegitStack
I’m hoping you guys can give me some general advice and perhaps code examples if you’re feeling up to it. I’m very interested in Elixir,...
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
LegitStack
I’m trying to make a websocket server in Phoenix or raw Elixir. I heard about gun, I think I could use cowboy, but since I’m not that sma...
New
kostonstyle
Hi all I want to have a unix time, from the current time plus 1 hour. DateTime.now + 1 hour How to get it in elixir? Thanks
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID&lt;0.412.0&gt; terminating ** (Postgrex.Error) FATAL...
New
Codball
Mix format works fine if run from the cmd. I’ve followed this to facilitate the implementation into VSC which involves downloading an ext...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New

Other popular topics Top

albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID&lt;0.412.0&gt; terminating ** (Postgrex.Error) FATAL...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New
Nvim
Elixir appears to be a superior language to Python. I don’t see any advantage of Python over Elixir. Are there any?
New

We're in Beta

About us Mission Statement