aio-libs / aiodns

Simple DNS resolver for asyncio
https://pypi.python.org/pypi/aiodns
MIT License
532 stars 69 forks source link

added examples to showcase how cool this dns library is #91

Open meramsey opened 3 years ago

meramsey commented 3 years ago

I love this library of all the ones i've tried it was the fastest easiest to use. I will say at first it took a bit to figure out how to best get all the results I wanted to reuse.

I think the examples would be super helpful for any people checking out the project and wanting something easy to use to see how they can do most anything easily.

The rdns/ptr lookups for example are glossed over on the examples but fully shown with functions for both using coroutines.

The domaindns.py has a really badass class I have been working on for my app which uses whois/rdap whois and aiodns. I have commented out the non aiodns stuff but left it in so people can see what's possible. If possible would be nice if this was included as some of these things will save people having to reinvent the wheel. For anyone else that already knows how to do this stuff it won't affect them negatively.

Keep up the great work with this library.

Examples:

From domaindns.py

print('')
print('DNS Records JSON:')
# print(json.dumps(domain_dict, default=str))
print(json.dumps(DomainInfo('google.com').domain_dict))

print('')
print('DNS Records JSON Pretty Print:')
print(json.dumps(DomainInfo('google.com').domain_dict, indent=4, sort_keys=False))

Output:

DNS Records JSON:
{"domain": "google.com", "DNS": {"SOA": {"nsname": "ns1.google.com", "hostmaster": "dns-admin.google.com", "serial": "343814713", "refresh": "900", "retry": "900", "expires": "1800", "minttl": "60", "ttl": "16"}, "NS": [["ns1.google.com", "216.239.32.10"], ["ns3.google.com", "216.239.36.10"], ["ns4.google.com", "216.239.38.10"], ["ns2.google.com", "216.239.34.10"]], "WWW": [["A", "www.google.com", "142.250.64.196"], ["A", "google.com", "142.250.64.238"], ["AAAA", "google.com", "2607:f8b0:4008:807::200e"]], "MX": [["MX", "alt3.aspmx.l.google.com", "40"], ["MX", "aspmx.l.google.com", "10"], ["MX", "alt4.aspmx.l.google.com", "50"], ["MX", "alt2.aspmx.l.google.com", "30"], ["MX", "alt1.aspmx.l.google.com", "20"]], "TXT": [["TXT", "_dmarc.google.com", "v=DMARC1; p=reject; rua=mailto:mailauth-reports@google.com"], ["TXT", "google.com", "v=spf1 include:_spf.google.com ~all"], ["TXT", "google.com", "globalsign-smime-dv=CDYX+XFHUw2wml6/Gb8+59BsH31KzUr6c1l2BPvqKX8="], ["TXT", "google.com", "docusign=05958488-4752-4ef2-95eb-aa7ba8a3bd0e"], ["TXT", "google.com", "docusign=1b0a6754-49b1-4db5-8540-d2c12664b289"], ["TXT", "google.com", "facebook-domain-verification=22rm551cu4k0ab0bxsw536tlds4h95"]]}}

DNS Records JSON Pretty Print:
{
    "domain": "google.com",
    "DNS": {
        "SOA": {
            "nsname": "ns1.google.com",
            "hostmaster": "dns-admin.google.com",
            "serial": "343814713",
            "refresh": "900",
            "retry": "900",
            "expires": "1800",
            "minttl": "60",
            "ttl": "15"
        },
        "NS": [
            [
                "ns2.google.com",
                "216.239.34.10"
            ],
            [
                "ns4.google.com",
                "216.239.38.10"
            ],
            [
                "ns3.google.com",
                "216.239.36.10"
            ],
            [
                "ns1.google.com",
                "216.239.32.10"
            ]
        ],
        "WWW": [
            [
                "A",
                "www.google.com",
                "142.250.64.196"
            ],
            [
                "A",
                "google.com",
                "142.250.64.238"
            ],
            [
                "AAAA",
                "google.com",
                "2607:f8b0:4008:807::200e"
            ]
        ],
        "MX": [
            [
                "MX",
                "alt1.aspmx.l.google.com",
                "20"
            ],
            [
                "MX",
                "alt2.aspmx.l.google.com",
                "30"
            ],
            [
                "MX",
                "alt4.aspmx.l.google.com",
                "50"
            ],
            [
                "MX",
                "aspmx.l.google.com",
                "10"
            ],
            [
                "MX",
                "alt3.aspmx.l.google.com",
                "40"
            ]
        ],
        "TXT": [
            [
                "TXT",
                "_dmarc.google.com",
                "v=DMARC1; p=reject; rua=mailto:mailauth-reports@google.com"
            ],
            [
                "TXT",
                "google.com",
                "facebook-domain-verification=22rm551cu4k0ab0bxsw536tlds4h95"
            ],
            [
                "TXT",
                "google.com",
                "docusign=1b0a6754-49b1-4db5-8540-d2c12664b289"
            ],
            [
                "TXT",
                "google.com",
                "docusign=05958488-4752-4ef2-95eb-aa7ba8a3bd0e"
            ],
            [
                "TXT",
                "google.com",
                "globalsign-smime-dv=CDYX+XFHUw2wml6/Gb8+59BsH31KzUr6c1l2BPvqKX8="
            ],
            [
                "TXT",
                "google.com",
                "v=spf1 include:_spf.google.com ~all"
            ]
        ]
    }
}