{"id":17722817,"url":"https://github.com/bramp/rustdns","last_synced_at":"2025-04-26T18:11:52.513Z","repository":{"id":57665199,"uuid":"371843329","full_name":"bramp/rustdns","owner":"bramp","description":"DNS Client in Rust","archived":false,"fork":false,"pushed_at":"2023-12-16T22:43:16.000Z","size":473,"stargazers_count":25,"open_issues_count":7,"forks_count":11,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-21T06:15:48.302Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bramp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"bramp","buy_me_a_coffee":"bramp"}},"created_at":"2021-05-28T23:58:38.000Z","updated_at":"2025-01-15T17:26:18.000Z","dependencies_parsed_at":"2024-10-25T19:59:08.659Z","dependency_job_id":"2953263f-db6d-4e30-bb14-639e2907441b","html_url":"https://github.com/bramp/rustdns","commit_stats":{"total_commits":57,"total_committers":3,"mean_commits":19.0,"dds":"0.052631578947368474","last_synced_commit":"46302f60c4b828b5210dce4618edf571b5a33070"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bramp%2Frustdns","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bramp%2Frustdns/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bramp%2Frustdns/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bramp%2Frustdns/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bramp","download_url":"https://codeload.github.com/bramp/rustdns/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250847208,"owners_count":21497141,"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":[],"created_at":"2024-10-25T15:39:28.159Z","updated_at":"2025-04-25T15:43:41.011Z","avatar_url":"https://github.com/bramp.png","language":"Rust","funding_links":["https://github.com/sponsors/bramp","https://buymeacoffee.com/bramp"],"categories":["Rust"],"sub_categories":[],"readme":"[![Crates.io](https://img.shields.io/crates/v/rustdns.svg)](https://crates.io/crates/rustdns)\n[![Documentation](https://docs.rs/rustdns/badge.svg)](https://docs.rs/rustdns)\n[![Build Status](https://github.com/bramp/rustdns/actions/workflows/rust.yml/badge.svg)](https://github.com/bramp/rustdns)\n\n# rustdns\n\n## rustdns\n\nrustdns is a simple, fast, and fully fledged DNS library for interacting\nwith domain name services at a high or low level.\n\n## Features\n* Parsing and generating the following record types:\n  * A,\n  * AAAA,\n  * CNAME,\n  * MX,\n  * NS,\n  * SOA,\n  * PTR,\n  * TXT, and\n  * SRV\n* Extension Mechanisms for DNS ([EDNS(0)]).\n* Support [International Domain Names (IDNA)](https://en.wikipedia.org/wiki/Internationalized_domain_name) - Different scripts, alphabets, anhd even emojis!\n* Sample `dig` style [command line](#usage-cli).\n* Fully [tested](#testing), and [fuzzed](#fuzzing).\n\n## Usage (low-level library)\n\n```rust\nuse rustdns::Message;\nuse rustdns::types::*;\nuse std::net::UdpSocket;\nuse std::time::Duration;\n\nfn udp_example() -\u003e std::io::Result\u003c()\u003e {\n    // A DNS Message can be easily constructed\n    let mut m = Message::default();\n    m.add_question(\"bramp.net\", Type::A, Class::Internet);\n    m.add_extension(Extension {   // Optionally add a EDNS extension\n        payload_size: 4096,       // which supports a larger payload size.\n        ..Default::default()\n    });\n\n    // Setup a UDP socket for sending to a DNS server.\n    let socket = UdpSocket::bind(\"0.0.0.0:0\")?;\n    socket.set_read_timeout(Some(Duration::new(5, 0)))?;\n    socket.connect(\"8.8.8.8:53\")?; // Google's Public DNS Servers\n\n    // Encode the DNS Message as a Vec\u003cu8\u003e.\n    let question = m.to_vec()?;\n\n    // Send to the server.\n    socket.send(\u0026question)?;\n\n    // Wait for a response from the DNS server.\n    let mut resp = [0; 4096];\n    let len = socket.recv(\u0026mut resp)?;\n\n    // Take the response bytes and turn it into another DNS Message.\n    let answer = Message::from_slice(\u0026resp[0..len])?;\n\n    // Now do something with `answer`, in this case print it!\n    println!(\"DNS Response:\\n{}\", answer);\n\n    Ok(())\n}\n```\n\nIf successful something like the following will be printed:\n\n```\n;; -\u003e\u003eHEADER\u003c\u003c- opcode: Query, status: NoError, id: 44857\n;; flags: qr rd ra ad; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1\n\n;; OPT PSEUDOSECTION:\n; EDNS: version: 0, flags:; udp: 512\n;; QUESTION SECTION:\n; bramp.net.              IN   A\n\n; ANSWER SECTION:\nbramp.net.            299 IN   A      104.21.62.200\nbramp.net.            299 IN   A      172.67.138.196\n```\n\n## Features\nThe following optional features are available:\n\n- `clients`: Enables the following clients:\n  - `doh`: DNS over HTTPS (DoH) client (rfc8484).\n  - `json`: DNS over HTTPS JSON client\n  - `tcp`: Enables the DNS over TCP client\n  - `udp`: Enables the DNS over UDP client\n- `zones`: Enable a Zone File Parser\n\n## Usage (cli)\n\nTo use the [demo CLI](https://github.com/bramp/rustdns/blob/main/src/rustdns/dig/main.rs):\n\n```shell\n$ cargo run -p dig -- A www.google.com\n...\n;; -\u003e\u003eHEADER\u003c\u003c- opcode: Query, status: NoError, id: 34327\n;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1\n\n;; OPT PSEUDOSECTION:\n; EDNS: version: 0, flags:; udp: 512\n;; QUESTION SECTION:\n; www.google.com.         IN   A\n\n; ANSWER SECTION:\nwww.google.com.       110 IN   A      142.250.72.196\n\n# More examples\n$ cargo run -p dig -- AAAA www.google.com\n$ cargo run -p dig -- ANY www.google.com\n$ cargo run -p dig -- CNAME code.google.com\n$ cargo run -p dig -- MX google.com\n$ cargo run -p dig -- PTR 4.4.8.8.in-addr.arpa\n$ cargo run -p dig -- SOA google.com\n$ cargo run -p dig -- SRV _ldap._tcp.google.com\n$ cargo run -p dig -- TXT google.com\n```\n## Testing\n\n```shell\n$ cargo test --all\n\n# or the handy\n$ cargo watch -- cargo test --all -- --nocapture\n```\n\nThe test suite is full of stored real life examples, from querying real DNS records.\nThis was generated with `cargo run -p generate_tests`.\n\n### Fuzzing\n\nThe library has been extensively fuzzed. Try for yourself:\n\n```shell\n$ cargo fuzz run from_slice\n```\n\n### Test Data\n\nTo aid in testing features, I have a set of pre-configured records setup:\n\n| Domain                | Description |\n| --------------------- | ----------- |\n| a.bramp.net           | Single A record pointing at 127.0.0.1 |\n| aaaa.bramp.net        | Single AAAA record pointing at ::1 |\n| aaaaa.bramp.net       | One A record, and one AAAA record resolving to 127.0.0.1 and ::1 |\n| cname.bramp.net       | Single CNAME record pointing at a.bramp.net |\n| cname-loop1.bramp.net | Single CNAME record pointing at cname-loop2.bramp.net |\n| cname-loop2.bramp.net | Single CNAME record pointing at cname-loop1.bramp.net |\n| mx.bramp.net          | Single MX record pointing at a.bramp.net |\n| ns.bramp.net          | Single NS record pointing at a.bramp.net |\n| txt.bramp.net         | Single TXT Record \"A TXT record!\" |\n\n## Releasing\n\n```shell\n# Bump version number\n$ cargo test-all-features\n$ cargo readme \u003e README.md\n$ cargo publish --dry-run\n$ cargo publish\n```\n\n## TODO (in order of priority)\n* [ ] Document UDP/TCP library\n* [ ] Client side examples\n* [ ] Server side examples\n* [ ] DNSSEC: Signing, validating and key generation for DSA, RSA, ECDSA and Ed25519\n* [ ] NSID, Cookies, AXFR/IXFR, TSIG, SIG(0)\n* [ ] Runtime-independence\n* [ ] Change the API to have getters and setters.\n* [ ] Change hyper-alpn to support tokio-native-tls for people that want that.\n* [ ] Implement more dig features, such as +trace\n* [ ] Maybe convert the binary parsing to Nom format.\n* [ ] Can I parse these https://www.iana.org/domains/root/files ?\n\n### Reference\n\n* [rfc1034]: DOMAIN NAMES - CONCEPTS AND FACILITIES\n* [rfc1035]: DOMAIN NAMES - IMPLEMENTATION AND SPECIFICATION\n* [rfc6895]: Domain Name System (DNS) IANA Considerations\n* [IANA Domain Name System (DNS) Parameters](https://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml)\n* [Computer Networks CPS365 FALL 2016](https://courses.cs.duke.edu//fall16/compsci356/DNS/DNS-primer.pdf)\n* [miekg's Go DNS Library](https://github.com/miekg/dns)\n\n[EDNS(0)]: https://en.wikipedia.org/wiki/Extension_Mechanisms_for_DNS\n[rfc1034]: https://datatracker.ietf.org/doc/html/rfc1034\n[rfc1035]: https://datatracker.ietf.org/doc/html/rfc1035\n[rfc6895]: https://datatracker.ietf.org/doc/html/rfc6895\n\n## License: Apache-2.0\n\n```\nCopyright 2021 Andrew Brampton (bramp.net)\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n    http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbramp%2Frustdns","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbramp%2Frustdns","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbramp%2Frustdns/lists"}