### Use Custom Client with DNSClient Context Manager Source: https://context7.com/pogzyb/whodap/llms.txt Demonstrates using a custom httpx.AsyncClient with the DNSClient context manager for asynchronous DNS lookups. Ensure the httpx library is installed. ```python import httpx import whodap import asyncio async def dns_client_with_custom_httpx(): async_client = httpx.AsyncClient(timeout=60.0) async with whodap.DNSClient.new_aio_client_context(async_client) as dns_client: response = await dns_client.aio_lookup('bitcoin', 'org') print(response.ldhName) asyncio.run(dns_client_with_custom_httpx()) ``` -------------------------------- ### Synchronous IPv4Client for Multiple Queries Source: https://context7.com/pogzyb/whodap/llms.txt Shows how to use a reusable synchronous IPv4Client for performing multiple IPv4 address lookups. It includes examples of direct client usage and context manager pattern. ```python import whodap # Synchronous client ipv4_client = whodap.IPv4Client.new_client() response = ipv4_client.lookup('8.8.8.8') print(response.to_dict()) ipv4_client.close() # Using context manager with whodap.IPv4Client.new_client_context() as ipv4_client: response = ipv4_client.lookup('1.1.1.1') print(response.to_json(indent=2)) ``` -------------------------------- ### DNSClient Initialization and Usage Source: https://github.com/pogzyb/whodap/blob/main/README.md Demonstrates how to initialize and use the `DNSClient` for performing RDAP DNS queries. ```APIDOC ## DNSClient ### Description A reusable client for RDAP DNS queries. ### Initialization Initialize an instance of `DNSClient` using classmethods: `new_client` (synchronous) or `new_aio_client` (asynchronous). ### Methods - **new_client()**: Creates a synchronous `DNSClient` instance. - **new_aio_client()**: Creates an asynchronous `DNSClient` instance. - **lookup(domain, tld)**: Performs a synchronous RDAP lookup for the given domain and TLD. ### Usage Example (Synchronous) ```python import whodap # Initialize a synchronous DNSClient dns_client = whodap.DNSClient.new_client() # Perform lookups domain_data = dns_client.lookup(domain='google', tld='com') print(domain_data.to_dict()) buzz_data = dns_client.lookup(domain='google', tld='buzz') print(buzz_data.to_dict()) ``` ### Usage Example (Asynchronous) ```python import asyncio import whodap async def main(): # Initialize an asynchronous DNSClient aio_dns_client = whodap.DNSClient.new_aio_client() # Perform asynchronous lookups domain_data = await aio_dns_client.lookup(domain='google', tld='com') print(domain_data.to_dict()) buzz_data = await aio_dns_client.lookup(domain='google', tld='buzz') print(buzz_data.to_dict()) asyncio.run(main()) ``` ``` -------------------------------- ### Custom httpx Client Configuration for Sync and Async Source: https://context7.com/pogzyb/whodap/llms.txt Shows how to configure a custom httpx.Client or httpx.AsyncClient for advanced settings like proxies, timeouts, and redirects, and use it with Whodap functions and clients. ```python import httpx import whodap import asyncio # Configure httpx client with proxy and custom timeout httpx_client = httpx.Client( proxies=httpx.Proxy('https://user:pw@proxy.example.com'), timeout=30.0, follow_redirects=True ) # Use with convenience function response = whodap.lookup_domain('example', 'com', httpx_client=httpx_client) print(response.to_whois_dict()) # Important: Close the client when done (you manage its lifecycle) httpx_client.close() # Async example with custom client async def lookup_with_proxy(): async_client = httpx.AsyncClient( proxies=httpx.Proxy('http://user:pw@proxy.example.com'), timeout=30.0 ) async with async_client: # Concurrent lookups through proxy tasks = [ whodap.aio_lookup_domain('google', 'com', httpx_client=async_client), whodap.aio_lookup_domain('amazon', 'com', httpx_client=async_client), ] results = await asyncio.gather(*tasks) for result in results: print(result.to_whois_dict()['domain_name']) asyncio.run(lookup_with_proxy()) ``` -------------------------------- ### IPv6Client Initialization and Usage Source: https://github.com/pogzyb/whodap/blob/main/README.md Demonstrates how to initialize and use the `IPv6Client` for performing RDAP IPv6 queries. ```APIDOC ## IPv6Client ### Description A reusable client for RDAP IPv6 queries. ### Initialization Initialize an instance of `IPv6Client` using classmethods: `new_client` (synchronous) or `new_aio_client` (asynchronous). ### Methods - **new_client()**: Creates a synchronous `IPv6Client` instance. - **new_aio_client()**: Creates an asynchronous `IPv6Client` instance. - **lookup(ipv6_address)**: Performs a synchronous RDAP lookup for the given IPv6 address. ### Usage Example (Synchronous) ```python import whodap # Initialize a synchronous IPv6Client ipv6_client = whodap.IPv6Client.new_client() # Perform lookup response = ipv6_client.lookup(ipv6_address='2001:4860:4860::8888') print(response.to_dict()) ``` ### Usage Example (Asynchronous) ```python import asyncio import whodap async def main(): # Initialize an asynchronous IPv6Client aio_ipv6_client = whodap.IPv6Client.new_aio_client() # Perform lookup response = await aio_ipv6_client.lookup(ipv6_address='2001:4860:4860::8888') print(response.to_dict()) asyncio.run(main()) ``` ``` -------------------------------- ### IPv4Client Initialization and Usage Source: https://github.com/pogzyb/whodap/blob/main/README.md Demonstrates how to initialize and use the `IPv4Client` for performing RDAP IPv4 queries. ```APIDOC ## IPv4Client ### Description A reusable client for RDAP IPv4 queries. ### Initialization Initialize an instance of `IPv4Client` using classmethods: `new_client` (synchronous) or `new_aio_client` (asynchronous). ### Methods - **new_client()**: Creates a synchronous `IPv4Client` instance. - **new_aio_client()**: Creates an asynchronous `IPv4Client` instance. - **lookup(ipv4_address)**: Performs a synchronous RDAP lookup for the given IPv4 address. ### Usage Example (Synchronous) ```python import whodap # Initialize a synchronous IPv4Client ipv4_client = whodap.IPv4Client.new_client() # Perform lookup response = ipv4_client.lookup(ipv4_address='8.8.8.8') print(response.to_dict()) ``` ### Usage Example (Asynchronous) ```python import asyncio import whodap async def main(): # Initialize an asynchronous IPv4Client aio_ipv4_client = whodap.IPv4Client.new_aio_client() # Perform lookup response = await aio_ipv4_client.lookup(ipv4_address='8.8.8.8') print(response.to_dict()) asyncio.run(main()) ``` ``` -------------------------------- ### ASNClient Initialization and Usage Source: https://github.com/pogzyb/whodap/blob/main/README.md Demonstrates how to initialize and use the `ASNClient` for performing RDAP ASN queries. ```APIDOC ## ASNClient ### Description A reusable client for RDAP ASN queries. ### Initialization Initialize an instance of `ASNClient` using classmethods: `new_client` (synchronous) or `new_aio_client` (asynchronous). ### Methods - **new_client()**: Creates a synchronous `ASNClient` instance. - **new_aio_client()**: Creates an asynchronous `ASNClient` instance. - **lookup(asn_number)**: Performs a synchronous RDAP lookup for the given AS number. ### Usage Example (Synchronous) ```python import whodap # Initialize a synchronous ASNClient asn_client = whodap.ASNClient.new_client() # Perform lookup response = asn_client.lookup(asn_number=15169) print(response.to_dict()) ``` ### Usage Example (Asynchronous) ```python import asyncio import whodap async def main(): # Initialize an asynchronous ASNClient aio_asn_client = whodap.ASNClient.new_aio_client() # Perform lookup response = await aio_asn_client.lookup(asn_number=15169) print(response.to_dict()) asyncio.run(main()) ``` ``` -------------------------------- ### Configuring httpx Client for Whodap Source: https://github.com/pogzyb/whodap/blob/main/README.md Illustrates initializing and using custom httpx clients (synchronous and asynchronous) with Whodap functions and DNSClient. ```python import asyncio import httpx import whodap # Initialize a custom, pre-configured httpx client ... httpx_client = httpx.Client(proxies=httpx.Proxy('https://user:pw@proxy_url.net')) # ... or an async client aio_httpx_client = httpx.AsyncClient(proxies=httpx.Proxy('http://user:pw@proxy_url.net')) # Three common methods for leveraging httpx clients are outlined below: # 1) Pass the httpx client directly into the convenience functions: `lookup_domain` or `aio_lookup_domain` # Important: In this scenario, you are responsible for closing the httpx client. # In this example, the given httpx client is used as a contextmanager; ensuring it is "closed" when finished. async with aio_httpx_client: futures = [] for domain, tld in [('google', 'com'), ('google', 'buzz')]: task = whodap.aio_lookup_domain(domain, tld, httpx_client=aio_httpx_client) futures.append(task) await asyncio.gather(*futures) ``` ```python # 2) Pass the httpx_client into the DNSClient classmethod: `new_client` or `new_aio_client` aio_dns_client = await whodap.DNSClient.new_aio_client(aio_httpx_client) result = await aio_dns_client.aio_lookup('google', 'buzz') await aio_httpx_client.aclose() ``` ```python # 3) Pass the httpx_client into the DNSClient contextmanagers: `new_client_context` or `new_aio_client_context` # This method ensures the underlying httpx_client is closed when exiting the "with" block. async with whodap.DNSClient.new_aio_client_context(aio_httpx_client) as dns_client: for domain, tld in [('google', 'com'), ('google', 'buzz')]: response = await dns_client.aio_lookup(domain, tld) ``` -------------------------------- ### Custom httpx Client Configuration Source: https://context7.com/pogzyb/whodap/llms.txt Demonstrates how to use a custom httpx client for advanced configuration, including proxies, custom timeouts, and authentication, with both synchronous and asynchronous operations. ```APIDOC ## Custom httpx Client Configuration ### Description All lookup functions and clients accept a custom `httpx` client for advanced configuration like proxies, custom timeouts, and authentication. ### Method Various (lookup, aio_lookup) ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python import httpx import whodap import asyncio # Configure httpx client with proxy and custom timeout httpx_client = httpx.Client( proxies=httpx.Proxy('https://user:pw@proxy.example.com'), timeout=30.0, follow_redirects=True ) # Use with convenience function response = whodap.lookup_domain('example', 'com', httpx_client=httpx_client) print(response.to_whois_dict()) # Important: Close the client when done (you manage its lifecycle) httpx_client.close() # Async example with custom client async def lookup_with_proxy(): async_client = httpx.AsyncClient( proxies=httpx.Proxy('http://user:pw@proxy.example.com'), timeout=30.0 ) async with async_client: # Concurrent lookups through proxy tasks = [ whodap.aio_lookup_domain('google', 'com', httpx_client=async_client), whodap.aio_lookup_domain('amazon', 'com', httpx_client=async_client), ] results = await asyncio.gather(*tasks) for result in results: print(result.to_whois_dict()['domain_name']) asyncio.run(lookup_with_proxy()) ``` ### Response #### Success Response (200) - **domain_name** (str) - The name of the domain. #### Response Example ```json { "domain_name": "example.com" } ``` ``` -------------------------------- ### Asynchronous DNSClient Lookup Source: https://github.com/pogzyb/whodap/blob/main/README.md Shows how to perform asynchronous domain lookups using the DNSClient with an async context manager. ```python dns_client = await whodap.DNSClient.new_aio_client() for domain, tld in [('google', 'com'), ('google', 'buzz')]: response = await dns_client.aio_lookup(domain, tld) ``` ```python async with whodap.DNSClient.new_aio_client_context() as dns_client: for domain, tld in [('google', 'com'), ('google', 'buzz')]: response = await dns_client.aio_lookup(domain, tld) ``` -------------------------------- ### Synchronous DNSClient Lookup Source: https://github.com/pogzyb/whodap/blob/main/README.md Demonstrates using the DNSClient with a synchronous context manager for domain lookups. ```python with whodap.DNSClient.new_client_context() as dns_client: for domain, tld in [('google', 'com'), ('google', 'buzz')]: response = dns_client.lookup(domain, tld) ``` -------------------------------- ### ASNClient for Multiple ASN Queries Source: https://context7.com/pogzyb/whodap/llms.txt Illustrates using the ASNClient with a context manager to perform multiple ASN lookups efficiently. ```python import whodap # Using context manager with whodap.ASNClient.new_client_context() as asn_client: for asn in [15169, 13335, 32934]: response = asn_client.lookup(asn) data = response.to_dict() print(f"AS{asn}: {data.get('name')}") ``` -------------------------------- ### Asynchronous DNSClient for Concurrent Lookups Source: https://context7.com/pogzyb/whodap/llms.txt Demonstrates using an asynchronous DNSClient for high-performance concurrent domain lookups. It supports both direct client management and an async context manager for automatic resource handling. ```python import asyncio import whodap async def batch_lookup(): # Create async DNS client dns_client = await whodap.DNSClient.new_aio_client() domains = [('google', 'com'), ('amazon', 'com'), ('github', 'io')] for domain, tld in domains: response = await dns_client.aio_lookup(domain, tld) print(f"{response.ldhName}: {response.status}") await dns_client.aio_close() asyncio.run(batch_lookup()) # Using async context manager (recommended) async def batch_lookup_context(): async with whodap.DNSClient.new_aio_client_context() as dns_client: response = await dns_client.aio_lookup('bitcoin', 'org') print(response.to_whois_dict()) asyncio.run(batch_lookup_context()) ``` -------------------------------- ### Async DNSClient Source: https://context7.com/pogzyb/whodap/llms.txt An asynchronous version of DNSClient for high-performance concurrent domain lookups. ```APIDOC ## DNSClient (Async) ### Description Async version of DNSClient for high-performance concurrent domain lookups. ### Method Various (aio_lookup) ### Endpoint N/A (Client object) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python import asyncio import whodap async def batch_lookup(): # Create async DNS client dns_client = await whodap.DNSClient.new_aio_client() domains = [('google', 'com'), ('amazon', 'com'), ('github', 'io')] for domain, tld in domains: response = await dns_client.aio_lookup(domain, tld) print(f"{response.ldhName}: {response.status}") await dns_client.aio_close() asyncio.run(batch_lookup()) # Using async context manager (recommended) async def batch_lookup_context(): async with whodap.DNSClient.new_aio_client_context() as dns_client: response = await dns_client.aio_lookup('bitcoin', 'org') print(response.to_whois_dict()) asyncio.run(batch_lookup_context()) ``` ### Response #### Success Response (200) - **ldhName** (str) - The LDH name of the domain. - **status** (str) - The status of the domain lookup. #### Response Example ```json { "ldhName": "bitcoin.org", "status": "available" } ``` ``` -------------------------------- ### Async Lookup Multiple ASNs Source: https://context7.com/pogzyb/whodap/llms.txt Demonstrates asynchronous lookup of multiple ASNs concurrently using asyncio.gather. Requires importing asyncio and whodap. ```python import asyncio import whodap async def lookup_multiple_asns(): asns = [15169, 13335, 32934] # Google, Cloudflare, Facebook tasks = [whodap.aio_lookup_asn(asn) for asn in asns] results = await asyncio.gather(*tasks) for asn, result in zip(asns, results): data = result.to_dict() print(f"AS{asn}: {data.get('name')}") asyncio.run(lookup_multiple_asns()) ``` -------------------------------- ### IPv6Client for RDAP IPv6 Queries Source: https://context7.com/pogzyb/whodap/llms.txt Demonstrates using the IPv6Client, preferably with a context manager, to perform RDAP queries for IPv6 addresses. ```python import whodap # Using context manager with whodap.IPv6Client.new_client_context() as ipv6_client: response = ipv6_client.lookup('2001:4860:4860::8888') print(response.to_dict()) ``` -------------------------------- ### Using DNSClient with whodap Source: https://github.com/pogzyb/whodap/blob/main/README.md Initializes a DNSClient instance using a classmethod and performs lookups for multiple domain-TLD pairs. This client is designed for reusable RDAP DNS queries. ```python import whodap # Initialize an instance of DNSClient using classmethods: `new_client` or `new_aio_client` dns_client = whodap.DNSClient.new_client() for domain, tld in [('google', 'com'), ('google', 'buzz')]: response = dns_client.lookup(domain, tld) ``` -------------------------------- ### Asynchronous Domain Lookup with whodap Source: https://context7.com/pogzyb/whodap/llms.txt Provides an async-compatible version of `lookup_domain` for use with asyncio. Ideal for high-performance concurrent domain lookups when querying multiple domains simultaneously. ```python import asyncio import whodap async def lookup_multiple_domains(): # Single async lookup response = await whodap.aio_lookup_domain(domain='google', tld='com') print(f"Domain: {response.ldhName}") # Concurrent lookups for multiple domains domains = [ ('bitcoin', 'org'), ('google', 'com'), ('amazon', 'com'), ] tasks = [ whodap.aio_lookup_domain(domain=d, tld=t) for d, t in domains ] results = await asyncio.gather(*tasks) for result in results: whois = result.to_whois_dict() print(f"{whois['domain_name']}: {whois['registrar_name']}") # Run the async function asyncio.run(lookup_multiple_domains()) ``` -------------------------------- ### Asynchronous Domain Lookup Source: https://context7.com/pogzyb/whodap/llms.txt Async-compatible version of `lookup_domain` for use with asyncio. Enables high-performance concurrent domain lookups when querying multiple domains simultaneously. ```APIDOC ## aio_lookup_domain ### Description Async-compatible version of `lookup_domain` for use with asyncio. Enables high-performance concurrent domain lookups when querying multiple domains simultaneously. ### Method GET (conceptual, as this is a library function) ### Endpoint N/A (Library Function) ### Parameters #### Query Parameters - **domain** (string) - Required - The domain name to query. - **tld** (string) - Required - The top-level domain of the domain. ### Request Example ```python import asyncio import whodap async def lookup_multiple_domains(): domains = [ ('bitcoin', 'org'), ('google', 'com'), ('amazon', 'com'), ] tasks = [ whodap.aio_lookup_domain(domain=d, tld=t) for d, t in domains ] results = await asyncio.gather(*tasks) for result in results: whois = result.to_whois_dict() print(f"{whois['domain_name']}: {whois['registrar_name']}") asyncio.run(lookup_multiple_domains()) ``` ### Response #### Success Response (200) - **response** (object) - An object representing the RDAP response, with attributes accessible via dot notation (e.g., `response.ldhName`, `response.status`). Includes methods like `to_dict()` and `to_whois_dict()`. #### Response Example (Same structure as `lookup_domain`) ``` -------------------------------- ### Asynchronous IPv6 Lookup Source: https://context7.com/pogzyb/whodap/llms.txt Async version of `lookup_ipv6` for asynchronous IPv6 address lookups. ```APIDOC ## aio_lookup_ipv6 ### Description Async version of `lookup_ipv6` for asynchronous IPv6 address lookups. ### Method GET (conceptual, as this is a library function) ### Endpoint N/A (Library Function) ### Parameters #### Path Parameters - **ip_address** (string or ipaddress.IPv6Address) - Required - The IPv6 address to query. ### Request Example ```python import asyncio import whodap async def lookup_ipv6_async(): response = await whodap.aio_lookup_ipv6('2001:4860:4860::8888') print(response.to_dict()) asyncio.run(lookup_ipv6_async()) ``` ### Response #### Success Response (200) - **response** (object) - An object representing the RDAP response for the IPv6 address. Can be converted to a dictionary using `to_dict()` or JSON using `to_json()`. #### Response Example (Same structure as `lookup_ipv6`) ``` -------------------------------- ### Lookup Domain with whodap Source: https://github.com/pogzyb/whodap/blob/main/README.md Demonstrates how to perform a synchronous and asynchronous RDAP lookup for a domain name using whodap. The response object can be traversed using dot notation or converted to a dictionary. ```python import asyncio from pprint import pprint import whodap # Looking up a domain name response = whodap.lookup_domain(domain='bitcoin', tld='org') # Equivalent asyncio call loop = asyncio.get_event_loop() response = loop.run_until_complete(whodap.aio_lookup_domain(domain='bitcoin', tld='org')) # "response" is a DomainResponse object. It contains the output from the RDAP lookup. print(response) # Traverse the DomainResponse via "dot" notation print(response.events) ``` ```python [ { "eventAction": "last update of RDAP database", "eventDate": "2021-04-23T21:50:03" }, { "eventAction": "registration", "eventDate": "2008-08-18T13:19:55" }, ... ] ``` ```python # Retrieving the registration date from above: print(response.events[1].eventDate) ``` ```python 2008-08-18 13:19:55 ``` ```python # Don't want "dot" notation? Use `to_dict` to get the RDAP response as a dictionary pprint(response.to_dict()) ``` ```python # Use `to_whois_dict` for the familiar look of WHOIS output pprint(response.to_whois_dict()) ``` ```python { abuse_email: 'abuse@namecheap.com', abuse_phone: 'tel:+1.6613102107', admin_address: 'P.O. Box 0823-03411, Panama, Panama, PA', admin_email: '2603423f6ed44178a3b9d728827aa19a.protect@whoisguard.com', admin_fax: 'fax:+51.17057182', admin_name: 'WhoisGuard Protected', admin_organization: 'WhoisGuard, Inc.', admin_phone: 'tel:+507.8365503', billing_address: None, billing_email: None, billing_fax: None, billing_name: None, billing_organization: None, billing_phone: None, created_date: datetime.datetime(2008, 8, 18, 13, 19, 55), domain_name: 'bitcoin.org', expires_date: datetime.datetime(2029, 8, 18, 13, 19, 55), nameservers: ['dns1.registrar-servers.com', 'dns2.registrar-servers.com'], registrant_address: 'P.O. Box 0823-03411, Panama, Panama, PA', registrant_email: '2603423f6ed44178a3b9d728827aa19a.protect@whoisguard.com', registrant_fax: 'fax:+51.17057182', registrant_name: 'WhoisGuard Protected', registrant_organization: None, registrant_phone: 'tel:+507.8365503', registrar_address: '4600 E Washington St #305, Phoenix, Arizona, 85034', registrar_email: 'support@namecheap.com', registrar_fax: None, registrar_name: 'NAMECHEAP INC', registrar_phone: 'tel:+1.6613102107', status: ['client transfer prohibited'], technical_address: 'P.O. Box 0823-03411, Panama, Panama, PA', technical_email: '2603423f6ed44178a3b9d728827aa19a.protect@whoisguard.com', technical_fax: 'fax:+51.17057182', technical_name: 'WhoisGuard Protected', technical_organization: 'WhoisGuard, Inc.', technical_phone: 'tel:+507.8365503', updated_date: datetime.datetime(2019, 11, 24, 13, 58, 35)} ``` -------------------------------- ### Synchronous DNSClient for Multiple Lookups Source: https://context7.com/pogzyb/whodap/llms.txt Uses a reusable synchronous DNSClient to perform multiple domain lookups efficiently by reusing HTTP connections. The client should be closed when done, or preferably used with a context manager. ```python import whodap # Create a synchronous DNS client dns_client = whodap.DNSClient.new_client() # Perform multiple lookups domains = [('google', 'com'), ('amazon', 'com'), ('github', 'io')] for domain, tld in domains: response = dns_client.lookup(domain, tld) whois = response.to_whois_dict() print(f"{whois['domain_name']}: {whois.get('registrar_name')}") # Always close the client when done dns_client.close() # Using context manager (recommended) with whodap.DNSClient.new_client_context() as dns_client: response = dns_client.lookup('example', 'com') print(response.to_whois_dict()) # Client automatically closed after the with block ``` -------------------------------- ### Asynchronous IPv4 Lookup Source: https://context7.com/pogzyb/whodap/llms.txt Async version of `lookup_ipv4` for asynchronous IPv4 address lookups. ```APIDOC ## aio_lookup_ipv4 ### Description Async version of `lookup_ipv4` for asynchronous IPv4 address lookups. ### Method GET (conceptual, as this is a library function) ### Endpoint N/A (Library Function) ### Parameters #### Path Parameters - **ip_address** (string or ipaddress.IPv4Address) - Required - The IPv4 address to query. ### Request Example ```python import asyncio import whodap async def check_ip_ranges(): ips = ['8.8.8.8', '1.1.1.1', '208.67.222.222'] tasks = [whodap.aio_lookup_ipv4(ip) for ip in ips] results = await asyncio.gather(*tasks) for ip, result in zip(ips, results): data = result.to_dict() print(f"{ip}: {data.get('name', 'Unknown')}") asyncio.run(check_ip_ranges()) ``` ### Response #### Success Response (200) - **response** (object) - An object representing the RDAP response for the IPv4 address. Can be converted to a dictionary using `to_dict()` or JSON using `to_json()`. #### Response Example (Same structure as `lookup_ipv4`) ``` -------------------------------- ### ASNClient Source: https://context7.com/pogzyb/whodap/llms.txt A reusable client for performing multiple RDAP ASN queries. ```APIDOC ## ASNClient ### Description Reusable client for performing multiple RDAP ASN queries. ### Method Various (lookup) ### Endpoint N/A (Client object) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python import whodap # Using context manager with whodap.ASNClient.new_client_context() as asn_client: for asn in [15169, 13335, 32934]: response = asn_client.lookup(asn) data = response.to_dict() print(f"AS{asn}: {data.get('name')}") ``` ### Response #### Success Response (200) - **handle** (str) - The handle associated with the ASN. - **name** (str) - The name of the organization associated with the ASN. #### Response Example ```json { "handle": "AS15169", "name": "GOOGLE" } ``` ``` -------------------------------- ### Asynchronous IPv6 Lookup with whodap Source: https://context7.com/pogzyb/whodap/llms.txt Async version of `lookup_ipv6` for asynchronous IPv6 address lookups. Enables concurrent querying of multiple IPv6 addresses. ```python import asyncio import whodap async def lookup_ipv6_async(): response = await whodap.aio_lookup_ipv6('2001:4860:4860::8888') print(response.to_dict()) asyncio.run(lookup_ipv6_async()) ``` -------------------------------- ### Asynchronous IPv4 Lookup with whodap Source: https://context7.com/pogzyb/whodap/llms.txt Async version of `lookup_ipv4` for asynchronous IPv4 address lookups. Useful for concurrently checking multiple IP addresses. ```python import asyncio import whodap async def check_ip_ranges(): ips = ['8.8.8.8', '1.1.1.1', '208.67.222.222'] tasks = [whodap.aio_lookup_ipv4(ip) for ip in ips] results = await asyncio.gather(*tasks) for ip, result in zip(ips, results): data = result.to_dict() print(f"{ip}: {data.get('name', 'Unknown')}") asyncio.run(check_ip_ranges()) ``` -------------------------------- ### Synchronous Domain Lookup with whodap Source: https://context7.com/pogzyb/whodap/llms.txt Performs a synchronous RDAP query for a domain name. Automatically discovers the RDAP server and follows referrals. Use this for single, non-concurrent domain lookups. ```python import whodap from pprint import pprint # Basic domain lookup response = whodap.lookup_domain(domain='bitcoin', tld='org') # Access RDAP response properties using dot notation print(f"Domain: {response.ldhName}") print(f"Status: {response.status}") # Get event dates (registration, expiration, etc.) for event in response.events: print(f"{event.eventAction}: {event.eventDate}") # Output: # last update of RDAP database: 2021-04-23 21:50:03 # registration: 2008-08-18 13:19:55 # expiration: 2029-08-18 13:19:55 # Convert to standard dictionary data = response.to_dict() pprint(data) # Convert to WHOIS-style flat dictionary whois_data = response.to_whois_dict() print(f"Registrar: {whois_data['registrar_name']}") print(f"Created: {whois_data['created_date']}") print(f"Expires: {whois_data['expires_date']}") print(f"Nameservers: {whois_data['nameservers']}") # Output: # Registrar: NAMECHEAP INC # Created: 2008-08-18 13:19:55 # Expires: 2029-08-18 13:19:55 # Nameservers: ['dns1.registrar-servers.com', 'dns2.registrar-servers.com'] ``` -------------------------------- ### Asynchronous IPv6 Lookup Source: https://github.com/pogzyb/whodap/blob/main/README.md Asynchronous counterpart to `lookup_ipv6` for non-blocking RDAP queries. ```APIDOC ## aio_lookup_ipv6 ### Description Asynchronous counterpart to `lookup_ipv6` for non-blocking RDAP queries. ### Method Asynchronous function call ### Endpoint N/A (Library function) ### Parameters #### Query Parameters - **ipv6_address** (string) - Required - The IPv6 address to look up. ### Request Example ```python import asyncio import whodap async def main(): response = await whodap.aio_lookup_ipv6(ipv6_address='2001:4860:4860::8888') print(response.to_dict()) asyncio.run(main()) ``` ### Response #### Success Response (200) - **IPv6Response object** - An object containing the RDAP response data. ``` -------------------------------- ### Asynchronous Domain Lookup Source: https://github.com/pogzyb/whodap/blob/main/README.md Asynchronous counterpart to `lookup_domain` for non-blocking RDAP queries. ```APIDOC ## aio_lookup_domain ### Description Asynchronous counterpart to `lookup_domain` for non-blocking RDAP queries. ### Method Asynchronous function call ### Endpoint N/A (Library function) ### Parameters #### Query Parameters - **domain** (string) - Required - The domain name to look up. - **tld** (string) - Required - The top-level domain (e.g., 'com', 'org'). ### Request Example ```python import asyncio import whodap async def main(): response = await whodap.aio_lookup_domain(domain='bitcoin', tld='org') print(response.to_dict()) asyncio.run(main()) ``` ### Response #### Success Response (200) - **DomainResponse object** - An object containing the RDAP response data, traversable via dot notation or convertible to a dictionary. ``` -------------------------------- ### DomainResponse Methods for Data Output Source: https://context7.com/pogzyb/whodap/llms.txt Illustrates various methods of the `DomainResponse` object for accessing and formatting RDAP data, including conversion to dictionaries, JSON strings, and WHOIS-style formats, as well as accessing nested properties. ```python import whodap response = whodap.lookup_domain('bitcoin', 'org') # Print as formatted JSON (uses __str__) print(response) # Convert to dictionary data_dict = response.to_dict() # Convert to JSON string with custom formatting json_str = response.to_json(indent=4) # Convert to WHOIS-style dictionary whois_dict = response.to_whois_dict() # Convert to WHOIS-style JSON string whois_json = response.to_whois_json(indent=2) # Access nested properties with dot notation print(f"Events: {response.events}") print(f"First event action: {response.events[0].eventAction}") print(f"First event date: {response.events[0].eventDate}" ) # Returns datetime object print(f"Nameservers: {[ns.ldhName for ns in response.nameservers]}") print(f"Status codes: {response.status}") ``` -------------------------------- ### DNSClient Source: https://context7.com/pogzyb/whodap/llms.txt A reusable client for performing multiple RDAP DNS queries, optimizing performance by reusing HTTP connections and cached IANA server mappings. ```APIDOC ## DNSClient ### Description A reusable client for performing multiple RDAP DNS queries. More efficient than using convenience functions when making multiple lookups as it reuses the HTTP connection and cached IANA server mappings. ### Method Various (lookup) ### Endpoint N/A (Client object) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python import whodap # Create a synchronous DNS client dns_client = whodap.DNSClient.new_client() # Perform multiple lookups domains = [('google', 'com'), ('amazon', 'com'), ('github', 'io')] for domain, tld in domains: response = dns_client.lookup(domain, tld) whois = response.to_whois_dict() print(f"{whois['domain_name']}: {whois.get('registrar_name')}") # Always close the client when done dns_client.close() # Using context manager (recommended) with whodap.DNSClient.new_client_context() as dns_client: response = dns_client.lookup('example', 'com') print(response.to_whois_dict()) # Client automatically closed after the with block ``` ### Response #### Success Response (200) - **domain_name** (str) - The name of the domain. - **registrar_name** (str) - The name of the registrar for the domain. #### Response Example ```json { "domain_name": "example.com", "registrar_name": "GoDaddy.com, LLC" } ``` ``` -------------------------------- ### Asynchronous IPv4 Lookup Source: https://github.com/pogzyb/whodap/blob/main/README.md Asynchronous counterpart to `lookup_ipv4` for non-blocking RDAP queries. ```APIDOC ## aio_lookup_ipv4 ### Description Asynchronous counterpart to `lookup_ipv4` for non-blocking RDAP queries. ### Method Asynchronous function call ### Endpoint N/A (Library function) ### Parameters #### Query Parameters - **ipv4_address** (string) - Required - The IPv4 address to look up. ### Request Example ```python import asyncio import whodap async def main(): response = await whodap.aio_lookup_ipv4(ipv4_address='8.8.8.8') print(response.to_dict()) asyncio.run(main()) ``` ### Response #### Success Response (200) - **IPv4Response object** - An object containing the RDAP response data. ``` -------------------------------- ### Synchronous Domain Lookup Source: https://context7.com/pogzyb/whodap/llms.txt Performs a synchronous RDAP query for a domain name and returns detailed registration information. Automatically discovers the appropriate RDAP server and follows referrals. ```APIDOC ## lookup_domain ### Description Performs a synchronous RDAP query for a domain name and returns detailed registration information including registrant contacts, nameservers, status codes, and event dates. The function automatically discovers the appropriate RDAP server for the given TLD and follows referrals to authoritative sources. ### Method GET (conceptual, as this is a library function) ### Endpoint N/A (Library Function) ### Parameters #### Query Parameters - **domain** (string) - Required - The domain name to query. - **tld** (string) - Required - The top-level domain of the domain. ### Request Example ```python import whodap response = whodap.lookup_domain(domain='bitcoin', tld='org') ``` ### Response #### Success Response (200) - **response** (object) - An object representing the RDAP response, with attributes accessible via dot notation (e.g., `response.ldhName`, `response.status`). Includes methods like `to_dict()` and `to_whois_dict()`. #### Response Example ```json { "ldhName": "bitcoin.org", "status": [ "clientDeleteProhibited", "clientTransferProhibited", "clientUpdateProhibited" ], "events": [ { "eventAction": "last update of RDAP database", "eventDate": "2021-04-23 21:50:03" }, { "eventAction": "registration", "eventDate": "2008-08-18 13:19:55" }, { "eventAction": "expiration", "eventDate": "2029-08-18 13:19:55" } ] } ``` ### WHOIS-Style Dictionary Example ```json { "domain_name": "bitcoin.org", "registrar_name": "NAMECHEAP INC", "created_date": "2008-08-18 13:19:55", "expires_date": "2029-08-18 13:19:55", "nameservers": [ "dns1.registrar-servers.com", "dns2.registrar-servers.com" ] } ``` ``` -------------------------------- ### Synchronous IPv6 Lookup with whodap Source: https://context7.com/pogzyb/whodap/llms.txt Performs an RDAP query for an IPv6 address. Retrieves network registration information. Accepts string or `ipaddress.IPv6Address` objects. ```python import whodap import ipaddress # Lookup IPv6 address response = whodap.lookup_ipv6('2001:4860:4860::8888') # Using ipaddress module ip = ipaddress.IPv6Address('2606:4700:4700::1111') response = whodap.lookup_ipv6(ip) print(response.to_json(indent=2)) ``` -------------------------------- ### IPv6Client Source: https://context7.com/pogzyb/whodap/llms.txt A reusable client for performing multiple RDAP IPv6 queries. ```APIDOC ## IPv6Client ### Description Reusable client for performing multiple RDAP IPv6 queries. ### Method Various (lookup) ### Endpoint N/A (Client object) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python import whodap # Using context manager with whodap.IPv6Client.new_client_context() as ipv6_client: response = ipv6_client.lookup('2001:4860:4860::8888') print(response.to_dict()) ``` ### Response #### Success Response (200) - **ip** (str) - The IP address. - **network** (str) - The network associated with the IP address. #### Response Example ```json { "ip": "2001:4860:4860::8888", "network": "2001:4860:4860::/64" } ``` ``` -------------------------------- ### Converting RDAP Response to WHOIS Dictionary Source: https://github.com/pogzyb/whodap/blob/main/README.md Demonstrates using the `to_whois_dict` method to convert RDAP responses to a WHOIS dictionary format. Includes handling of `RDAPConformanceException` when `strict=True`. ```python import logging from whodap import lookup_domain from whodap.errors import RDAPConformanceException logger = logging.getLogger(__name__) # strict = False (default) rdap_response = lookup_domain("example", "com") whois_format = rdap_response.to_whois_dict() logger.info(f"whois={whois_format}") # Given a valid RDAP response, the `to_whois_dict` method will attempt to # convert the RDAP format into a flattened dictionary of WHOIS key/values # strict = True try: # Unfortunately, there are instances in which the RDAP protocol is not # properly implemented by the registrar. By default, the `to_whois_dict` # will still attempt to parse the into the WHOIS dictionary. However, # there is no guarantee that the information will be correct or non-null. # If your applications rely on accurate information, the `strict=True` # parameter will raise an `RDAPConformanceException` when encountering # invalid or incorrectly formatted RDAP responses. rdap_response = lookup_domain("example", "com") whois_format = rdap_response.to_whois_dict(strict=True) except RDAPConformanceException: logger.exception("RDAP response is incorrectly formatted.") ``` -------------------------------- ### IPv4Client Source: https://context7.com/pogzyb/whodap/llms.txt A reusable client for performing multiple RDAP IPv4 queries. ```APIDOC ## IPv4Client ### Description Reusable client for performing multiple RDAP IPv4 queries. ### Method Various (lookup) ### Endpoint N/A (Client object) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python import whodap # Synchronous client ipv4_client = whodap.IPv4Client.new_client() response = ipv4_client.lookup('8.8.8.8') print(response.to_dict()) ipv4_client.close() # Using context manager with whodap.IPv4Client.new_client_context() as ipv4_client: response = ipv4_client.lookup('1.1.1.1') print(response.to_json(indent=2)) ``` ### Response #### Success Response (200) - **ip** (str) - The IP address. - **network** (str) - The network associated with the IP address. #### Response Example ```json { "ip": "8.8.8.8", "network": "8.8.8.0/24" } ``` ``` -------------------------------- ### Safe Domain Lookup with Error Handling Source: https://context7.com/pogzyb/whodap/llms.txt Provides a robust domain lookup function that handles various whodap exceptions, including `NotFoundError`, `RateLimitError`, `MalformedQueryError`, `BadStatusCode`, and general `WhodapError`. Returns a dictionary or None. ```python import whodap from whodap.errors import ( NotFoundError, RateLimitError, MalformedQueryError, BadStatusCode, WhodapError, RDAPConformanceException ) def safe_domain_lookup(domain: str, tld: str) -> dict | None: try: response = whodap.lookup_domain(domain, tld) return response.to_whois_dict() except NotFoundError: print(f"Domain {domain}.{tld} not found in RDAP") return None except RateLimitError: print("Rate limited by RDAP server, try again later") return None except MalformedQueryError: print(f"Invalid query format for {domain}.{tld}") return None except BadStatusCode as e: print(f"Unexpected HTTP status: {e}") return None except WhodapError as e: print(f"RDAP lookup failed: {e}") return None # Example usage result = safe_domain_lookup('nonexistent-domain-xyz', 'com') if result: print(f"Registrar: {result['registrar_name']}") ```