Skip to main content

DNS over HTTPS based on aiohttp and async_dns

Project description

async-doh

PyPI

DNS over HTTPS based on aiohttp and async_dns.

Installation

$ pip install async-doh

Usage

Command-line

usage: python3 -m async_doh.client [-h] [-n NAMESERVERS [NAMESERVERS ...]] [-t TYPES [TYPES ...]] hostnames [hostnames ...]

Async DNS resolver with DoH

positional arguments:
  hostnames             the hostnames to query

optional arguments:
  -h, --help            show this help message and exit
  -n NAMESERVERS [NAMESERVERS ...], --nameservers NAMESERVERS [NAMESERVERS ...]
                        name servers
  -t TYPES [TYPES ...], --types TYPES [TYPES ...]
                        query types, default as `any`

Examples:

$ python3 -m async_doh.client -n https://223.5.5.5/dns-query -t ANY -- www.google.com

Client

import asyncio
import aiohttp
from async_doh.client import DoHClient

async def main():
    async with DoHClient() as client:
        result = await client.query('https://1.1.1.1/dns-query', 'www.google.com', 'A')
        print('query:', result)
        result = await client.query_json('https://1.1.1.1/dns-query', 'www.google.com', 'A')
        print('query_json:', result)

asyncio.run(main())

Server

from aiohttp import web
from async_doh.server import application

web.run(application)

Now you have http://localhost:8080/dns-query as an endpoint.

Patching async_dns

By importing the patch, async_dns will use aiohttp to send queries through HTTPS (aka DNS over HTTPS):

import asyncio
from async_dns.core import types
from async_dns.resolver import ProxyResolver
from async_doh.client import patch

async def main():
    revoke = await patch()
    resolver = ProxyResolver(proxies=['https://dns.alidns.com/dns-query'])
    res, _ = await resolver.query('www.google.com', types.A)
    print(res)
    await revoke()

asyncio.run(main())

References

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

async-doh-0.3.0.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

async_doh-0.3.0-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file async-doh-0.3.0.tar.gz.

File metadata

  • Download URL: async-doh-0.3.0.tar.gz
  • Upload date:
  • Size: 6.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.7 CPython/3.9.6 Darwin/20.5.0

File hashes

Hashes for async-doh-0.3.0.tar.gz
Algorithm Hash digest
SHA256 e2ff660409bf778f1a356c353b5798ad028a87f2ddb15795a1aef1f773c77d00
MD5 9c68a16620683436ade6e1aef61f14c9
BLAKE2b-256 0f805093a7b6bd523f2b599a1f04cfa27c237961e980ec00aaa159cbdff28f14

See more details on using hashes here.

File details

Details for the file async_doh-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: async_doh-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.7 CPython/3.9.6 Darwin/20.5.0

File hashes

Hashes for async_doh-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e0570fc9a91a429af736a3822a000d390196db449fbbcd3ea077d50d9970794e
MD5 a18a72981901fea237fbc67882fa7957
BLAKE2b-256 baa094c57a37497c577df4d23ee555c9a2086bb70a74b969f2c0999c4114a06b

See more details on using hashes here.

Supported by

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