Skip to content
Quickly Search Large DNS Datasets
Branch: master
Clone or download
erbbysam Merge pull request #5 from C0RB3N/master
Add IndexHandler, config file, custom message
Latest commit c982dc7 Mar 12, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
DNSBinarySearch initial commit Feb 9, 2019
experimentalServer Add error checking Mar 11, 2019
LICENSE initial commit Feb 9, 2019
dnsgrep.go initial commit Feb 9, 2019


A utility for quickly searching presorted DNS names. Built around the Rapid7 rdns & fdns dataset.

How does it work?

This utility assumes the file provided is presorted (both alphabetical, and symbols).

The algorithm is pretty simple:

  1. Use a binary search algorithm to seek through the file, looking for a substring match against the query.
  2. Once a match is found, the file is scanned backwards in 10KB increments looking for a non-matching substring.
  3. Once a non-matching substring is found, the file is scanned forwards until all exact matches are returned.


There is a built-in limit system. This prevents 2 things:

  1. scanning too far backwards (MaxScan)
  2. scanning too far forwards after scanning backwards (MaxOutputLines)

This allows for any input while stopping requests that are taking too long.

Additionally, this utility does not handle the edge cases(start/end) of files and will return an error if encountered.


go get the following packages:

# used for dnsgrep cli flags
go get ""
# used by the experimental server for http routing
go get ""
# pull in a string reversal function
go get ""


The following steps were tested with Ubuntu 16.04 & go 1.11.5.

Generate fdns_a.sort.txt and rdns.sort.txt first using the scripts found in the scripts/ folder:

# Each of these scripts requires:
# * 3 hours+ on an SSD
# * 300GB+ temp disk space (under the same folder)
# * ~65GB  for output output (under the same folder)
# * jq to be installed

Run the command line utility:

go run dnsgrep.go -f DNSBinarySearch/test_data.txt -i ""

Run the experimental server in the same folder as fdns_a.sort & rdns.sort.txt:

go run experimentalServer.go

Data Source

The source of this data referenced throughout this repository is Rapid7 Labs. Please review the Terms of Service:

Stack Overflow References


  • we need to sort with LC_COLLATE=C to also sort ., chars


  • To sort a large file: split it into chunks, sort the chunks and then simply merge the results


See LICENSE file.

You can’t perform that action at this time.