Skip to main content

An easy way to customize the dns resolution

Project description

Build Coverage Status PyPI version

hookdns

HookDNS is a library which allow you to modify a name resolution in your Python script without any modification in your hosts file or by using a fake DNS resolver.

import requests

from hookdns import hosts

with hosts({"example.org": "127.0.0.1"}):
    ...
    r = requests.get("http://example.org")  # the request is sent to your local server
    ...

Installation

pip install hookdns

Usage

Custom DNS resolutions are describe by a dictionnary where the keys are hostnames and the values the expected corresponding addresses.

{
    "hostname1": "addr1",
    "hostname2": "addr2"
}

hostname and addr could be a domain name or a string representation of an IPv4/IPV6.

Example using the patch as a decorator

import requests

from hookdns import hosts

@hosts({"example.org": "127.0.0.1"})
def myfunc():
    ...
    r = requests.get("http://example.org")  # the request is sent to your local server
    ...

Example using the patch as a context manager

import requests

from hookdns import hosts

with hosts({"example.org": "localhost"}):
    ...
    r = requests.get("http://example.org")  # the request is sent to your local server
    ...

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

hookdns-2.0.2.tar.gz (9.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hookdns-2.0.2-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

Details for the file hookdns-2.0.2.tar.gz.

File metadata

  • Download URL: hookdns-2.0.2.tar.gz
  • Upload date:
  • Size: 9.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for hookdns-2.0.2.tar.gz
Algorithm Hash digest
SHA256 9116f443d67ec2aacad162cab067d6f12200dcf72ca1bc194a5dbef77b7d513b
MD5 7958159edbd41fd57e041daa74d4e6b3
BLAKE2b-256 608dddae796c0dce333ab97b9a5a33aae666e3f1333fd4e601fd685eade8ebe3

See more details on using hashes here.

Provenance

The following attestation bundles were made for hookdns-2.0.2.tar.gz:

Publisher: build.yml on cle-b/hookdns

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file hookdns-2.0.2-py3-none-any.whl.

File metadata

  • Download URL: hookdns-2.0.2-py3-none-any.whl
  • Upload date:
  • Size: 9.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for hookdns-2.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9d4008e1b00a35a209644d61c31e8356703f53bd9a80062c02585cf48e430488
MD5 ed77c6598b81d8aaa5366d4af67e8b94
BLAKE2b-256 add184222d79e3dec52c419e412d43cad56d4d783cdd4ee41c2a4e786d636668

See more details on using hashes here.

Provenance

The following attestation bundles were made for hookdns-2.0.2-py3-none-any.whl:

Publisher: build.yml on cle-b/hookdns

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page