{"id":21657972,"url":"https://github.com/tungd/elixir-dns","last_synced_at":"2025-07-17T20:32:31.620Z","repository":{"id":3725799,"uuid":"50708624","full_name":"tungd/elixir-dns","owner":"tungd","description":"DNS library for Elixir","archived":false,"fork":false,"pushed_at":"2023-05-20T15:55:05.000Z","size":94,"stargazers_count":111,"open_issues_count":19,"forks_count":37,"subscribers_count":7,"default_branch":"main","last_synced_at":"2024-04-26T01:42:46.890Z","etag":null,"topics":["dns","dns-client","dns-library","elixir"],"latest_commit_sha":null,"homepage":null,"language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tungd.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2016-01-30T04:20:10.000Z","updated_at":"2024-03-01T09:44:11.000Z","dependencies_parsed_at":"2023-07-05T18:17:08.593Z","dependency_job_id":null,"html_url":"https://github.com/tungd/elixir-dns","commit_stats":{"total_commits":77,"total_committers":16,"mean_commits":4.8125,"dds":0.4155844155844156,"last_synced_commit":"a32f6998dbecedaf177edc2c9436dc057eea500b"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tungd%2Felixir-dns","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tungd%2Felixir-dns/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tungd%2Felixir-dns/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tungd%2Felixir-dns/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tungd","download_url":"https://codeload.github.com/tungd/elixir-dns/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226304219,"owners_count":17603536,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dns","dns-client","dns-library","elixir"],"created_at":"2024-11-25T09:28:25.736Z","updated_at":"2024-11-25T09:28:28.544Z","avatar_url":"https://github.com/tungd.png","language":"Elixir","funding_links":[],"categories":["Elixir"],"sub_categories":[],"readme":"# DNS\n\n[![Build Status](https://github.com/tungd/elixir-dns/actions/workflows/elixir.yml/badge.svg?branch=main)](https://github.com/tungd/elixir-dns/actions)\n[![Module Version](https://img.shields.io/hexpm/v/dns.svg)](https://hex.pm/packages/dns)\n[![Hex Docs](https://img.shields.io/badge/hex-docs-lightgreen.svg)](https://hexdocs.pm/dns/)\n[![Total Download](https://img.shields.io/hexpm/dt/dns.svg)](https://hex.pm/packages/dns)\n[![License](https://img.shields.io/hexpm/l/dns.svg)](https://github.com/tungd/elixir-dns/blob/master/LICENSE)\n[![Last Updated](https://img.shields.io/github/last-commit/tungd/elixir-dns.svg)](https://github.com/tungd/elixir-dns/commits/master)\n\nDNS library for Elixir.\n\nCurrently, the package provides:\n\n- Elixir structs to interface with `:inet_dns` module\n- `DNS.Server` behavior\n- DNS client\n\nNote: the `:inet_dns` module is considered internal to Erlang and subject to\nchange. If this happened this library will be updated to accommodate for that,\nbut for now `:inet_dns` is simple and worked for me.\n\n## Installation\n\nMake sure you have the Erlang/OTP source files installed, otherwise the\ncompilation will fail with an `{:error, :enoent}` message. On Ubuntu, this can\nbe done using `apt-get install erlang-src`.\n\nAdd `:dns` to your list of dependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [\n    {:dns, \"~\u003e 2.4.0\"}\n  ]\nend\n```\n\n## Usage\n\n### DNS client\n\n```elixir\niex\u003e DNS.resolve(\"google.com\")\n{:ok, [{216, 58, 221, 110}]}\n\niex\u003e DNS.resolve(\"notfound.domain\")\n{:error, :not_found}\n\niex\u003e DNS.query(\"google.com\")\n%DNS.Record{anlist: [%DNS.Resource{bm: [], class: :in, cnt: 0,\n   data: {216, 58, 221, 110}, domain: 'google.com', func: false, tm: :undefined,\n   ttl: 129, type: :a}], arlist: [],\n header: %DNS.Header{aa: false, id: 0, opcode: :query, pr: false, qr: true,\n  ra: true, rcode: 0, rd: false, tc: false}, nslist: [],\n qdlist: [%DNS.Query{class: :in, domain: 'google.com', type: :a}]}\n\niex\u003e DNS.resolve(\"google.com\", :a, {\"8.8.8.8\", 53})\n...\n```\n\n### DNS server\n\n```elixir\ndefmodule ServerExample do\n  @moduledoc \"\"\"\n  Example implementing DNS.Server behaviour\n  \"\"\"\n  @behaviour DNS.Server\n  use DNS.Server\n\n  def handle(record, _cl) do\n    Logger.info(fn -\u003e \"#{inspect(record)}\" end)\n    query = hd(record.qdlist)\n\n    result =\n      case query.type do\n        :a -\u003e {127, 0, 0, 1}\n        :cname -\u003e 'your.domain.com'\n        :txt -\u003e ['your txt value']\n        _ -\u003e nil\n      end\n\n    resource = %DNS.Resource{\n      domain: query.domain,\n      class: query.class,\n      type: query.type,\n      ttl: 0,\n      data: result\n    }\n\n    %{record | anlist: [resource], header: %{record.header | qr: true}}\n  end\nend\n```\n\nTo run the example server in `iex`:\n\n```elixir\niex\u003e c \"example/test_server.ex\"\n[ServerExample]\niex\u003e {:ok, server_pid} = ServerExample.start_link 8000\nServer listening at 8000\n{:ok, #PID\u003c0.180.0\u003e}\niex\u003e Process.exit(server_pid, :normal)\n```\n\n## Copyright and License\n\nCopyright (c) 2016-2022 Tung Dao and contributors.\n\nThis library is released under the BSD 3-Clause \"New\" or \"Revised\" License. See\nthe [LICENSE.md](./LICENSE.md) file for further details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftungd%2Felixir-dns","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftungd%2Felixir-dns","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftungd%2Felixir-dns/lists"}