Skip to main content

Sensible high-level DNS lookups in Python, using DNSpython resolver

Project description


PyPi package

Simple, sensible high-level DNS lookups in Python (on top of dnspython dns.resolver).

Purpose and scope

This library is a simple wrapper around dnspython, to provide high level functions with good error/exception handling, for the most common basic DNS lookup cases.

  • A, AAAA record lookups (typical DNS queries)
  • SOA lookups

This is not intended to be a complete wrapper around dnspython library or to handle uncommon edge cases. Features like DoH are out of scope, and should be done using other libraries or dnspython directly.


Returns an object containing two arrays:

  • response_full: the full DNS response string(s)
  • answer: the parsed DNS answer (list of IPs or SOA string)
from nslookup import Nslookup

domain = ""

# Initialize Nslookup
dns_query = Nslookup()
# Alternatively, the Nslookup constructor supports optional
# arguments for setting custom dns servers (defaults to system DNS),
# verbosity (default: True) and using TCP instead of UDP (default: False)
dns_query = Nslookup(dns_servers=[""], verbose=False, tcp=False)

ips_record = dns_query.dns_lookup(domain)
print(ips_record.response_full, ips_record.answer)

soa_record = dns_query.soa_lookup(domain)
print(soa_record.response_full, soa_record.answer)


This library is oriented around regular UDP DNS.

Using TCP modes in this simple library will create a separate TCP session for each query, which can be resource intensive for a large number of queries. For this it is recommended to use the more granular dnspython API directly.

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

nslookup-1.7.0.tar.gz (8.8 kB view hashes)

Uploaded Source

Built Distribution

nslookup-1.7.0-py3-none-any.whl (9.2 kB view hashes)

Uploaded Python 3

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