A simple Go utility for performing reverse DNS (PTR) lookups, both in single and batch mode.
- Single IP lookup:
dns-reverse <ip> [dns-server] - Batch mode: Process a file of IP addresses (plain text or CSV) and output results to CSV.
- Custom DNS server: Specify an alternative DNS server for lookups.
- Configurable timeout: Set the timeout for each DNS query.
- Parallel processing: Batch mode uses a worker pool for concurrent lookups (configurable number of workers).
- Verbose output: Optional logging for debugging.
- Version information: Print the version with
-version. - Robust input handling: Accepts plain text (one IP per line) or CSV (first column), ignores empty lines and comments (lines starting with
#).
go install github.com/yourusername/dns-reverse@latestOr build from source:
go build -o dns-reversedns-reverse 8.8.8.8
dns-reverse 8.8.8.8 8.8.4.4 # Use 8.8.4.4 as the DNS serverdns-reverse -batch -i input.txt -o output.csv
dns-reverse -batch -i input.txt -o output.csv -s 1.1.1.1 -w 20 -t 30sThe tool automatically detects the format based on file extension:
.csvfiles are parsed as CSV (first column = IP)- All other files are treated as plain text (one IP per line)
Plain text (examples/example_ips.txt):
8.8.8.8
8.8.4.4
1.1.1.1
CSV (examples/example_ips.csv):
IP,Description
8.8.8.8,Google Public DNS
8.8.4.4,Google Public DNS SecondaryLines starting with # are treated as comments and ignored. Empty lines are also ignored.
The output CSV always has three columns:
IP: The input IP address.Hostname: The PTR record(s) found, separated by;if multiple.Status:OKfor success,No hostnameif no PTR record, orError: <description>for failures.
| Flag | Description | Default |
|---|---|---|
-batch |
Run in batch mode (requires -i and -o) |
false |
-i |
Input file path (batch mode) | "" |
-o |
Output file path (batch mode) | "" |
-s |
Custom DNS server (IP address) | "" (system default) |
-t |
Timeout for each DNS query (e.g., 30s, 1m30s) |
10s |
-w |
Number of concurrent workers (batch mode) | 10 |
-v |
Verbose output (logs progress and debug info) | false |
-version |
Print version and exit | false |
dns-reverse -t 5s 9.9.9.9 8.8.8.8dns-reverse -batch -i ips.csv -o results.csv -w 15 -v# Using plain text input
dns-reverse -batch -i examples/example_ips.txt -o examples/output.csv
# Using CSV input
dns-reverse -batch -i examples/example_ips.csv -o examples/output.csvSee the examples/ directory for sample input files:
example_ips.txt- Plain text formatexample_ips.csv- CSV formatexample_output.csv- Expected output format
Run the unit tests:
go test ./...MIT