https://github.com/cirocosta/rawdns
A records resolver from scratch - raw UDP packets
https://github.com/cirocosta/rawdns
dns go golang name-resolution networking
Last synced: about 1 year ago
JSON representation
A records resolver from scratch - raw UDP packets
- Host: GitHub
- URL: https://github.com/cirocosta/rawdns
- Owner: cirocosta
- License: mit
- Created: 2017-12-29T13:04:39.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2019-12-13T19:43:55.000Z (over 6 years ago)
- Last Synced: 2025-03-30T22:32:28.663Z (over 1 year ago)
- Topics: dns, go, golang, name-resolution, networking
- Language: Go
- Homepage: https://ops.tips/blog/raw-dns-resolver-in-go/
- Size: 21.5 KB
- Stars: 21
- Watchers: 4
- Forks: 3
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
rawdns 📡
DNS messages (un)marshaller and UDP client
### Overview
`rawdns` a small DNS client library that performs A records queries against a given nameserver.
It relies only on `net` to perform the UDP queries, constructing and parsing all the messages in transit manually.
This is a project that is **not** intended to be used in production **at all**. It's not as efficient as it should and does not handle all the cases you'd expect from a production-ready library.
For real use, see [miekg/dns](https://github.com/miekg/dns).
### Usage
CLI:
```sh
rawdns example.com
msg sent labels=[example com]
&{ID:0 QR:1 Opcode:0 AA:0 TC:0 RD:1 RA:1 Z:0 RCODE:0 QDCOUNT:1 ANCOUNT:1 NSCOUNT:0 ARCOUNT:0}
ANSWER: [93 184 216 34]
```
Programatically:
```go
import "github.com/cirocosta/rawdns/lib"
client, err := lib.NewClient(lib.ClientConfig{
Address: "8.8.8.8:53",
})
must(err)
defer client.Close()
ips, err := client.LookupAddr("example.com")
must(err)
for _, ip := range ips {
fmt.Println(ip)
}
```