Cache domain to IP mappings
Project description
DNSCacher
DNSCacher is a command-line utility that helps you manage domain-to-IP mappings efficiently. It supports caching results in a local file, updating those results on demand, removing stale entries, and refreshing entries in user-defined parts of the cache. Additionally, it can produce various output formats (e.g., mappings, IP addresses, domain lists, and ipset commands) to standard output.
Table of Contents
Features
-
Domain-to-IP Caching
Store resolved IP addresses for a list of domains, preventing repeated DNS lookups. -
Incremental Updates
Only resolves domains that are not yet in your cache. Removes stale domains that no longer appear in your source list. -
Partial Refresh
Re-resolve only a random subset (percentage) of your cached domains to keep them fresh without resolving everything every time. -
Multiple Output Formats
Can output mappings, IP addresses, domain lists, or an ipset command. -
Parallelism
Specify a number of parallel jobs (--jobs) to resolve domains concurrently.
Installation
pip install dnscacher
or
Clone the repository and install it locally:
pip install .
If you want to develop the code, you can install the development dependencies by running:
pip install -e ".[dev]"
This will install the development dependencies together with the package in editable mode.
Usage
Run the dnscacher command with one of the subcommands:
dnscacher [OPTIONS] {get|add|update|refresh} [SOURCE]
- The
SOURCEis either a local file or a URL and is not needed for thegetorrefreshcommands.
Basic Workflow
- Add a new source of domains or start from an existing one.
- Update to handle changes in a domain list.
- Get the stored cache data to your console.
- Refresh in parts to re-resolve subsets of the cache if needed.
Commands
Below are the primary commands. Each command also accepts common options described in Options.
GET
Command: dnscacher get
-
Description:
Retrieves the current domain-to-IP mappings from the cache and (optionally) prints them to stdout in the format(s) you choose. -
Key Points:
- Does not resolve or remove domains.
- Use
--outputto choose what you want to see: e.g.,mappings,ips,domains, oripset.
ADD
Command: dnscacher add [SOURCE]
-
Description:
Resolves and adds any domains not already in the cache.
If the--debugflag is set, theSOURCEis ignored, anddebug.txtis used. -
Behavior:
- Reads from
SOURCE(URL or file). - Only new domains (compared to the existing cache) are resolved.
- The newly resolved IPs are appended to the cache.
- Does not remove any domains already in the cache.
- Reads from
UPDATE
Command: dnscacher update [SOURCE]
-
Description:
Combines adding new domains and removing stale domains in one step. -
Behavior:
- Reads from
SOURCE(URL or file). - Resolves any new domains, just like in ADD.
- Removes any domains from your cache that are no longer in
SOURCE. - Maintains the rest of the domains.
- Reads from
REFRESH
Command: dnscacher refresh
-
Description:
Re-resolves a random set (size is given by--part) of already cached domains. -
Behavior:
- Does not add or remove domains, only re-resolves ones that exist in the cache.
- Useful if you want to verify that the IPs in your cache are still correct, without re-resolving all of them.
Options
To get get information on the options run the dnscacher --help command.
Source Argument
- Some commands like ADD or UPDATE optionally take a
SOURCEargument. - This
SOURCEcan be:- A local file path (e.g.,
/path/to/file.txt) - A URL (e.g.,
https://example.com/domains.txt)
- A local file path (e.g.,
- If the
--debugflag is set, theSOURCEprovided is ignored, and the tool uses the localdebug.txtfile from the project.
Output Formats
Use -o/--output with one or more comma-separated values:
mappings: Prints the domain followed by all its IP addresses (e.g.,example.com 93.184.216.34).ips: Prints only the IP addresses in the cache, one per line.domains: Prints only the domains in the cache, one per line.ipset: Printsadd <ipsetName> <ip>lines. Useful for piping intoipsetcommands.
If you provide multiple outputs, separate them with commas:
dnscacher --output mappings,ipset get
That will print the mappings block, then the ipset block.
Examples
1. Add a List of Domains from a URL
dnscacher add https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/porn-only/hosts
- Resolves all new domains found in that URL and appends them to the cache.
2. Get the Current Mappings in ipset Format
dnscacher --output ipset get
- Prints lines of the form
add dnscacher 93.184.216.34.
3. Update Cache from a Local File
dnscacher update /path/to/domains.txt
- Adds any new domains from
domains.txtand removes any that no longer appear in it.
4. Refresh 50% of Cached Domains
dnscacher --part 50 refresh
- Randomly picks 50% of the cached domains and re-resolves them, updating the cache with potentially new IP addresses.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dnscacher-0.3.0.tar.gz.
File metadata
- Download URL: dnscacher-0.3.0.tar.gz
- Upload date:
- Size: 21.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
943f77d4eb1f85859c3361f57a016d61350504109e09e16f01e44d4369d85e36
|
|
| MD5 |
8a59ecfedb944bad4e2cf3dea93d140b
|
|
| BLAKE2b-256 |
864e649eadb99aaf14b1f1c18cf37c166d9bcf2646bd86fc4a104e9c55ff3d94
|
Provenance
The following attestation bundles were made for dnscacher-0.3.0.tar.gz:
Publisher:
release.yml on BartSte/dnscacher
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dnscacher-0.3.0.tar.gz -
Subject digest:
943f77d4eb1f85859c3361f57a016d61350504109e09e16f01e44d4369d85e36 - Sigstore transparency entry: 171372513
- Sigstore integration time:
-
Permalink:
BartSte/dnscacher@e00d81128da8f786bf45ca06fbf7eb2e078b5aa0 -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/BartSte
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@e00d81128da8f786bf45ca06fbf7eb2e078b5aa0 -
Trigger Event:
push
-
Statement type:
File details
Details for the file dnscacher-0.3.0-py3-none-any.whl.
File metadata
- Download URL: dnscacher-0.3.0-py3-none-any.whl
- Upload date:
- Size: 18.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
973d27899cf40df6ea3779277e8b2b97dae8013fe6e13e1463352adc43dbf050
|
|
| MD5 |
2e3a8fadf1f1381800a1295478869b61
|
|
| BLAKE2b-256 |
0d9ed71da9ffe440e701e7d847c5d50e87423d0f7ed691dfe6a982bff4e75a56
|
Provenance
The following attestation bundles were made for dnscacher-0.3.0-py3-none-any.whl:
Publisher:
release.yml on BartSte/dnscacher
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dnscacher-0.3.0-py3-none-any.whl -
Subject digest:
973d27899cf40df6ea3779277e8b2b97dae8013fe6e13e1463352adc43dbf050 - Sigstore transparency entry: 171372514
- Sigstore integration time:
-
Permalink:
BartSte/dnscacher@e00d81128da8f786bf45ca06fbf7eb2e078b5aa0 -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/BartSte
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@e00d81128da8f786bf45ca06fbf7eb2e078b5aa0 -
Trigger Event:
push
-
Statement type: