mirror of
https://github.com/andwati/dns-resolver.git
synced 2026-11-22 18:28:46 +00:00
send the request to a name server and dump the response out.
This commit is contained in:
@@ -1 +1,39 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/andwati/dns-resolver/internal/dns"
|
||||||
|
"github.com/andwati/dns-resolver/internal/network"
|
||||||
|
"log"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
domain := "dns.google.com"
|
||||||
|
|
||||||
|
header := dns.DNSHeader{
|
||||||
|
ID: dns.GenerateRandomID(),
|
||||||
|
Flags: 0x0100,
|
||||||
|
QDCount: 1,
|
||||||
|
}
|
||||||
|
|
||||||
|
question := dns.DNSQuestion{
|
||||||
|
QName: domain,
|
||||||
|
QType: dns.QTypeA,
|
||||||
|
QClass: dns.QClassIN,
|
||||||
|
}
|
||||||
|
|
||||||
|
message := dns.DNSMessage{
|
||||||
|
Header: header,
|
||||||
|
Question: question,
|
||||||
|
}
|
||||||
|
|
||||||
|
serializedMessage := message.Serialize()
|
||||||
|
|
||||||
|
response, err := network.SendDNSQuery(serializedMessage, network.DefaultServer)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Error sending DNS query: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("DNS Response: %x\n", response)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user