logo
0
0
WeChat Login

go-dig

A simple DNS lookup tool similar to Linux dig command, implemented in Go.

Features

  • Query DNS records with various record types (A, AAAA, CNAME, MX, NS, TXT, etc.)
  • Support for custom DNS servers
  • Short output mode for simplified results
  • Reverse DNS lookup (PTR records)
  • Cross-platform support (Windows/Linux)

Installation

go build -o dig main.go

Usage

Basic DNS Query

dig example.com # Query A record using system DNS dig example.com A # Explicitly query A record dig example.com AAAA # Query AAAA record dig example.com MX # Query MX record dig example.com NS # Query NS record dig example.com TXT # Query TXT record

Specify DNS Server

dig @8.8.8.8 example.com # Use Google's DNS dig @1.1.1.1 example.com A # Use Cloudflare's DNS dig @8.8.8.8:53 example.com A # Specify custom port

Short Output Mode

dig +short example.com # Show only IP addresses dig +short example.com MX # Show MX records in short format dig +short example.com TXT # Show TXT records in short format

Reverse DNS Lookup

dig -x 8.8.8.8 # Find hostname for IP dig @8.8.8.8 -x 8.8.8.8 # Reverse lookup using specific DNS

DNS Server Detection

When no DNS server is specified, go-dig will:

  1. Use system configured DNS servers (Linux: /etc/resolv.conf, Windows: Get-DnsClientServerAddress)
  2. Fall back to 119.29.29.29 (Chinese public DNS) if system DNS is unavailable

Output Format

Full Output (default)

Shows detailed DNS response including:

  • Query statistics and flags
  • Question section
  • Answer section
  • Authority section
  • Additional section
  • Query time and server info

Short Output (+short)

Shows only the essential record data:

  • A/AAAA records: IP addresses
  • CNAME records: Canonical name
  • MX records: Priority and mail server
  • TXT records: Text content
  • NS records: Name servers
  • PTR records: Hostnames

License

This project is licensed under the MIT License - see the LICENSE file for details.

This is a simple educational project demonstrating DNS query implementation using miekg/dns library.

About

A simple DNS lookup tool similar to Linux `dig` command, implemented in Go.

164.00 KiB
0 forks0 stars1 branches1 TagREADMEMIT license
Language
Go100%