Example #1
0
def domain_abuse(domain, registrant=False):
    parts = extract(domain)
    domain = parts.registered_domain

    try:
        data = get_whois_raw(domain)
        parsed = parse_raw_whois(data, ['Domain', 'contacts'])
    except Exception as e:
        print("Could not get WHOIS for {} ({})".format(domain, e))

        return {
            "value": domain,
            "names": [],
            "abuse": [],
            "raw": ""
        }

    if registrant:
        results = _get_registrant_abuse(domain, parsed)
    else:
        results = _get_registrar_abuse(domain, parsed)

    results['raw'] = "\n\n".join(data)

    return results
Example #2
0
def domain_abuse(domain, registrant=False):
    parts = extract(domain)
    domain = parts.registered_domain

    try:
        data = get_whois_raw(domain)
        parsed = parse_raw_whois(data, ['Domain', 'contacts'])
    except Exception, e:
        print "Could not get WHOIS for {} ({})".format(domain, e)

        return {"value": domain, "names": [], "abuse": [], "raw": ""}
 def check_whois_V1(domain: str):
     if domain is not None and len(domain) > 0:
         try:
             server = net.get_root_server(domain)
             raw = net.get_whois_raw(domain, server=server)
             parsed = parse.parse_raw_whois(raw_data=raw)
             if len(parsed) > 0:
                 return False, None, True
             else:
                 return True, None, True
         except:
             return False, None, True
    def check_whois(domain: str):
        """

        :param domain:
        :return: True domain might avaiable to buy now, date time of expire, True if action is 100% sure
        """
        if domain is not None and len(domain) > 0:
            try:
                match = re.match(
                    "^[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,10}$", domain)
                if match is None:
                    raise ValueError("domain name error.")
                server = net.get_root_server(domain)
                raw = net.get_whois_raw(domain, server=server)
                parsed = parse.parse_raw_whois(raw_data=raw)
                expire_record = parsed.get("expiration_date")
                name_servers = parsed.get("nameservers")
                if len(parsed) <= 1:
                    return True, None, True
                else:
                    if expire_record is not None and len(expire_record) > 0:
                        temp = expire_record[0]
                    else:
                        if name_servers is None:
                            return True, None, True
                        else:
                            return False, None, False

                    expire_dates = len(expire_record)
                    if expire_dates > 1:
                        for i in range(1, expire_dates):
                            data = expire_record[i]
                            if data > temp:
                                temp = data
                    date = datetime.datetime.utcnow()
                    if temp is not None:
                        if date < temp:
                            #print(domain + " is not expired")
                            return False, temp, True
                        else:
                            if name_servers is None:
                                return True, temp, True
                            else:
                                return True, temp, False
                    else:
                        return True, None, False
            except Exception as ex:
                msg = "error in LinkChecker.check_whois(), checking " + domain
                ErrorLogger.log_error("LinkChecker", ex, msg)
                return False, None, False
        else:
            return False, None, True
Example #5
0
def domain_availability(domain):
    try:
        raw = get_whois_raw(domain)[0]
        phrase_to_check = 'No match for "%s"' % domain.upper()
        is_available = phrase_to_check in raw
        if is_available:
            availability = AVAILABLE
        else:
            availability = UNAVAILABLE
    except (socket_error, UnicodeDecodeError, WhoisException) as e:
        print "Whois error while checking %s: %s" % (domain, e)
        availability = UNKNOWN
    return availability
Example #6
0
    def run(self, tld):
        _abuse_contact = ""
        names = list()
        emails = list()

        try:
            data = get_whois_raw(tld)
            parsed_whois = parse_raw_whois(data, ['Domain', 'contacts'])

            _abuse_contact = parsed_whois['emails'][0]
        except Exception as e:
            self.logger.error('Abuse finder ended with error %s', e)
            return False, _abuse_contact

        return True, _abuse_contact
Example #7
0
def get_whois(domain: str) -> Dict:
    logger.debug(f"Retrieving Whois info for '{domain}'...")
    raw_whois, servers = get_whois_raw(domain, with_server_list=True)
    whois = {
        "raw": raw_whois[0] if len(raw_whois) > 0 else "",
        "servers": servers
    }
    logger.debug(f'Whois raw info:\n{whois["raw"]}')
    logger.debug(f'Whois servers: {whois["servers"]}')

    logger.debug(f"Retrieving Whois root server for '{domain}'...")
    root_server = get_root_server(domain)
    logger.debug(f"Whois root server: {root_server}")
    if len(whois["servers"]) > 0 and whois["servers"][0] != root_server:
        whois["servers"].insert(0, root_server)

    return whois
Example #8
0
File: whois.py Project: zy0001/yeti
    def analyze(hostname, results):
        links = set()

        parts = extract(hostname.value)

        if parts.subdomain == '':
            should_add_context = False
            for context in hostname.context:
                if context['source'] == 'whois':
                    break
            else:
                should_add_context = True
                context = {'source': 'whois'}

            data = get_whois_raw(hostname.value)
            results.update(raw=data[0])
            parsed = parse_raw_whois(data, normalized=True)
            context['raw'] = data[0]

            if 'creation_date' in parsed:
                context['creation_date'] = parsed['creation_date'][0]
            if 'registrant' in parsed['contacts']:
                fields_to_extract = [
                    ('email', Email, 'Registrant Email'),
                    ('name', Text, 'Registrant Name'),
                    ('organization', Text, 'Registrant Organization'),
                    ('phone', Text, 'Registrant Phone Number'),
                ]

                for field, klass, description in fields_to_extract:
                    links.update(
                        link_from_contact_info(
                            hostname, parsed['contacts']['registrant'], field,
                            klass, description))

            if should_add_context:
                hostname.add_context(context)
            else:
                hostname.save()

        return list(links)
Example #9
0
    def analyze(hostname):
        links = []

        parts = extract(hostname.value)

        if parts.subdomain == "":
            should_add_context = False
            for context in hostname.context:
                if context["source"] == "Whois":
                    break
            else:
                should_add_context = True
                context = {"source": "Whois"}

            data = get_whois_raw(hostname.value)
            parsed = parse_raw_whois(data, normalized=True)
            context["raw"] = data[0]

            if "creation_date" in parsed:
                context["creation_date"] = parsed["creation_date"][0]
            if "registrant" in parsed["contacts"]:
                fields_to_extract = [
                    ("email", Email, "Registrant", "Registrant Email"),
                    ("name", Text, "Registrant", "Registrant Name"),
                    ("organization", Text, "Registrant", "Registrant Organization"),
                    ("phone", Text, "Registrant", "Registrant Phone Number"),
                ]

                for field, klass, tag, description in fields_to_extract:
                    link = link_from_contact_info(
                        hostname, parsed["contacts"]["registrant"], field, klass, tag, description
                    )
                    if link is not None:
                        links.append(link)

            if should_add_context:
                hostname.add_context(context)
            else:
                hostname.save()

        return links
Example #10
0
    def analyze(hostname, results):
        links = set()

        parts = extract(hostname.value)

        if parts.subdomain == '':
            should_add_context = False
            for context in hostname.context:
                if context['source'] == 'whois':
                    break
            else:
                should_add_context = True
                context = {'source': 'whois'}

            data = get_whois_raw(hostname.value)
            results.update(raw=data[0])
            parsed = parse_raw_whois(data, normalized=True)
            context['raw'] = data[0]

            if 'creation_date' in parsed:
                context['creation_date'] = parsed['creation_date'][0]
            if 'registrant' in parsed['contacts']:
                fields_to_extract = [
                    ('email', Email, 'Registrant Email'),
                    ('name', Text, 'Registrant Name'),
                    ('organization', Text, 'Registrant Organization'),
                    ('phone', Text, 'Registrant Phone Number'),
                ]

                for field, klass, description in fields_to_extract:
                    links.update(
                        link_from_contact_info(
                            hostname, parsed['contacts']['registrant'], field,
                            klass, description))

            if should_add_context:
                hostname.add_context(context)
            else:
                hostname.save()

        return list(links)
    def is_domain_available_whois(domain: str) -> (bool, bool):
        """
        availability check with whois.
        :param domain: domain name to check, e.g: google.com.
        make sure the domain is in lower case in the first place.
        :return:True if the domain is available, True if domain in is redemption
        """
        if domain is not None and len(domain) > 0:
            try:
                match = re.match(
                    "^[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,10}$", domain)
                if match is None:
                    raise ValueError("domain name error.")
                #gr0 = match.group(0)
                server = net.get_root_server(domain)
                raw_data = net.get_whois_raw(domain, server=server)
                available = False
                is_redemption = False
                force_break = False
                status = ""
                fomat_line = ""
                all_lines = []
                patterns = [
                    status_pattern, available_pattern0, available_pattern1
                ]
                raw_data = [segment.replace("\r", "") for segment in raw_data
                            ]  # Carriage returns are the devil
                for segment in raw_data:
                    all_lines += str(segment).splitlines()

                for pattern in patterns:
                    # if status is not None and len(status) > 0:
                    #     break
                    if available or is_redemption or force_break:
                        break
                    for line in all_lines:
                        if len(line) == 0:
                            continue
                        temp = line.strip()
                        if temp.endswith(":"):
                            fomat_line = temp
                            continue
                        if fomat_line.endswith(":"):
                            fomat_line += temp
                        else:
                            fomat_line = temp
                        if fomat_line.startswith("%"):
                            continue
                        else:
                            fomat_line = fomat_line.lower()
                            if pattern is status_pattern:
                                match_status = re.search(
                                    status_pattern, fomat_line)
                                if match_status is not None:
                                    status = match_status.group(2)
                                    if status is not None and len(status) > 0:
                                        if re.search(status_value_pattern,
                                                     status) is not None:
                                            available = True
                                            break
                                        elif re.search(redemption_pattern,
                                                       status) is not None:
                                            is_redemption = True
                                            break
                                        elif re.search(
                                                other_official_status_pattern,
                                                status) is not None:
                                            force_break = True
                                            break
                            elif re.search(pattern, fomat_line) is not None:
                                available = True
                                break

                # if status is not None and len(status) > 0:
                #     if re.search(status_value_pattern, status) is not None:
                #         available = True
                #     elif re.search(redemption_pattern, status) is not None:
                #         is_redemption = True

                return available, is_redemption
            except ValueError:
                return False, False
            except Exception as ex:
                ErrorLogger.log_error("LinkChecker", ex,
                                      "is_domain_available_whois() " + domain)
                return False, False
        else:
            return False