How to use the tld.exceptions function in tld

To help you get started, we’ve selected a few tld examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github 0xInfection / XSRFProbe / xsrfprobe / core / options.py View on Github external
if args.output:
            # If output directory is mentioned...
            try:
                if not os.path.exists(args.output+tld.get_fld(config.SITE_URL)):
                    os.makedirs(args.output+tld.get_fld(config.SITE_URL))
            except FileExistsError:
                pass
            config.OUTPUT_DIR = args.output+tld.get_fld(config.SITE_URL) + '/'
        else:
            try:
                os.makedirs('xsrfprobe-output/'+tld.get_fld(config.SITE_URL))
            except FileExistsError:
                pass
            config.OUTPUT_DIR = 'xsrfprobe-output/'+tld.get_fld(config.SITE_URL) + '/'
    # When this exception turns out, we know the user has supplied a IP not domain
    except tld.exceptions.TldDomainNotFound:
        direc = re.search(IP, config.SITE_URL).group(0)
        if args.output:
            # If output directory is mentioned...
            try:
                if not os.path.exists(args.output+direc):
                    os.makedirs(args.output+direc)
            except FileExistsError:
                pass
            config.OUTPUT_DIR = args.output+direc + '/'
        else:
            try:
                os.makedirs('xsrfprobe-output/'+direc)
            except FileExistsError:
                pass
            config.OUTPUT_DIR = 'xsrfprobe-output/'+direc + '/'
github penafieljlm / inquisitor / inquisitor / assets / host.py View on Github external
def canonicalize(host):
    if not host:
        raise HostValidateException('Hosts cannot be None')
    if not isinstance(host, str) and not isinstance(host, unicode):
        raise HostValidateException('Hosts must be strings')
    host = host.strip().lower()
    try:
        tld.get_tld('http://{}'.format(host))
    except tld.exceptions.TldDomainNotFound:
        raise HostValidateException('Invalid tld for host {}'.format(host))
    return host
github 0xInfection / XSRFProbe / core / options.py View on Github external
if args.output:
            # If output directory is mentioned...
            try:
                if not os.path.exists(args.output+tld.get_fld(config.SITE_URL)):
                    os.makedirs(args.output+tld.get_fld(config.SITE_URL))
            except FileExistsError:
                pass
            config.OUTPUT_DIR = args.output+tld.get_fld(config.SITE_URL) + '/'
        else:
            try:
                os.makedirs('output/'+tld.get_fld(config.SITE_URL))
            except FileExistsError:
                pass
            config.OUTPUT_DIR = 'output/'+tld.get_fld(config.SITE_URL) + '/'
    # When this exception turns out, we know the user has supplied a IP not domain
    except tld.exceptions.TldDomainNotFound:
        direc = re.search(IP, config.SITE_URL).group(0)
        if args.output:
            # If output directory is mentioned...
            try:
                if not os.path.exists(args.output+direc):
                    os.makedirs(args.output+direc)
            except FileExistsError:
                pass
            config.OUTPUT_DIR = args.output+direc + '/'
        else:
            try:
                os.makedirs('output/'+direc)
            except FileExistsError:
                pass
            config.OUTPUT_DIR = 'output/'+direc + '/'
github j0lv3r4 / dnscheck / index.py View on Github external
def post_auth_ns():
    domain = request.forms.get("domain")

    if domain is None:
        return jsonify(status=400, message="Param domain missing.")

    try:
        nameserver_list = get_authoritative_nameserver(domain)
    except exceptions.TldDomainNotFound as e:
        print("TldDomainNotFound", e)
        return jsonify(status=400, message=str(e))
    except exceptions.TldBadUrl as e:
        print("TldBadUrl", e)
        return jsonify(status=400, message=str(e))

    return jsonify(status=200, message=nameserver_list)
github j0lv3r4 / dnscheck / index.py View on Github external
def index():
    domain = request.forms.get("domain")
    dns_server = request.forms.get("dns_server")

    if domain is None:
        return jsonify(status=400, message="Param domain missing.")

    if dns_server is None:
        return jsonify(status=400, message="Param dns_server missing.")

    try:
        domain = validate_domain(domain)
        dns_results = resolve_domain(domain, dns_server=dns_server)
        return jsonify(status=200, data=dns_results)
    except exceptions.TldDomainNotFound as e:
        print("TldDomainNotFound", e)
        return jsonify(status=400, message=str(e))
    except exceptions.TldBadUrl as e:
        print("TldBadUrl", e)
        return jsonify(status=400, message=str(e))
    except dns.resolver.NXDOMAIN as e:
        print("NXDOMAIN", e)
        return jsonify(status=404, message=e.msg)
    except dns.resolver.NoAnswer as e:
        print("NoAnswer", e)
        return jsonify(status=500, message=e.msg)
    except dns.resolver.NoNameservers as e:
        print("NoNameservers", e)
        return jsonify(status=500, message=e.msg)
    except Timeout as e:
        print("Timeout", e)
github j0lv3r4 / dnscheck / index.py View on Github external
dns_server = request.forms.get("dns_server")

    if domain is None:
        return jsonify(status=400, message="Param domain missing.")

    if dns_server is None:
        return jsonify(status=400, message="Param dns_server missing.")

    try:
        domain = validate_domain(domain)
        dns_results = resolve_domain(domain, dns_server=dns_server)
        return jsonify(status=200, data=dns_results)
    except exceptions.TldDomainNotFound as e:
        print("TldDomainNotFound", e)
        return jsonify(status=400, message=str(e))
    except exceptions.TldBadUrl as e:
        print("TldBadUrl", e)
        return jsonify(status=400, message=str(e))
    except dns.resolver.NXDOMAIN as e:
        print("NXDOMAIN", e)
        return jsonify(status=404, message=e.msg)
    except dns.resolver.NoAnswer as e:
        print("NoAnswer", e)
        return jsonify(status=500, message=e.msg)
    except dns.resolver.NoNameservers as e:
        print("NoNameservers", e)
        return jsonify(status=500, message=e.msg)
    except Timeout as e:
        print("Timeout", e)
        return jsonify(
            status=504,
            message="{} A common reason for this is an invalid DNS server.".format(

tld

Extract the top-level domain (TLD) from the URL given.

MPL-1.1 OR GPL-2.0-only OR LG…
Latest version published 2 years ago

Package Health Score

78 / 100
Full package analysis