elceef / dnstwist

Domain name permutation engine for detecting homograph phishing attacks, typo squatting, and brand impersonation
https://dnstwist.it
Apache License 2.0
4.73k stars 753 forks source link

fix: Avoid printing result when not using as CLI #223

Closed Zaulao closed 1 week ago

Zaulao commented 1 week ago

Avoid printing results to stdout when the tool is not being used as a CLI.

When the tool is used as a lib, it prevents stdout from being written unnecessarily since the value is already returned at the end of the execution of run() and can be handled appropriately by the function that started the execution.

Before:

>>> import dnstwist
>>> result = dnstwist.run(domain='paypal.com', registered=True, format='json')
[
    {
        "dns_a": [
            "151.101.129.21"
        ],
        "dns_mx": [
            "mx1.paypalcorp.com"
        ],
        "dns_ns": [
            "ns1.p57.dynect.net"
        ],
        ...
        ...
        ...
    }
]
>>> print(result[5].get('domain'))
paypalt.com

After:

>>> import dnstwist
>>> result = dnstwist.run(domain='paypal.com', registered=True, format='json')
>>> print(result[5].get('domain'))
paypalt.com
elceef commented 1 week ago

This change breaks the command line tool when --format argument is used effectively muting the output, for example:

$ ./dnstwist.py --format csv github.com

If you need API to not print to standard output, use format='null' as suggested in the documentation.