Python源码示例:pythonwhois.get_whois()

示例1
def whois(self, ctx, domain:str):
        """Gets whois information on a domain"""
        try:
            info = pythonwhois.get_whois(domain)
        except pythonwhois.shared.WhoisException:
            await ctx.send(Language.get("information.root_server_not_found", ctx))
            return
        except KeyError:
            await ctx.send(Language.get("information.failed_domain_lookup", ctx))
            return
        if info["contacts"]["registrant"] is None:
            await ctx.send(embed=discord.Embed(title=Language.get("information.domain_available_title", ctx), description=Language.get("information.domain_available_description", ctx).format(domain), color=0x00FF00))
            return
        fields = {Language.get("information.registrar", ctx):info["registrar"][0], Language.get("information.registered_on", ctx):format_time(info["creation_date"][0]), Language.get("information.expires_on", ctx):format_time(info["expiration_date"][0]), Language.get("information.last_updated", ctx):format_time(info["updated_date"][0]), Language.get("information.name_servers", ctx):", ".join(info["nameservers"])}
        embed = make_list_embed(fields)
        embed.title = Language.get("information.domain_unavailable", ctx)
        embed.color = 0xFF0000
        await ctx.send(embed=embed) 
示例2
def query_whois(self, query):

        try:

            whois_result = get_whois(domain=query)

            if "raw" in whois_result:

                if "No match" in str(whois_result["raw"][0]):
                    return None

                else:
                    return whois_result

            else:

                return None

        except UnicodeDecodeError, e:

            self.logger.debug(e)
            return None 
示例3
def whois(text):
    """<domain> -- Does a whois query on <domain>."""
    domain = text.strip().lower()

    try:
        data = pythonwhois.get_whois(domain, normalized=True)
    except pythonwhois.shared.WhoisException:
        return "Invalid input."
    info = []

    # We suppress errors here because different domains provide different data fields
    with suppress(KeyError):
        info.append("\x02Registrar\x02: {}".format(data["registrar"][0]))

    with suppress(KeyError):
        info.append("\x02Registered\x02: {}".format(data["creation_date"][0].strftime("%d-%m-%Y")))

    with suppress(KeyError):
        info.append("\x02Expires\x02: {}".format(data["expiration_date"][0].strftime("%d-%m-%Y")))

    info_text = ", ".join(info)
    return "{} - {}".format(domain, info_text) 
示例4
def findwhois():
	os.system('clear') 
	CORE_STRING = colored("[web_whois]", 'blue')
       	TARGET = raw_input(CORE_STRING + " Website> ")
	domains = [TARGET]
	for dom in domains:
		details = pythonwhois.get_whois(dom)
	        print details['contacts']['registrant'] 
示例5
def check_whois_domains(domains):
    # TODO - Check apex domains once instead of for each domain stored (the same apex domain may appear several times)
    for domain in domains:
        details = pythonwhois.get_whois(domain.apex_domain)
        if details.get('status') is None:
            print("[!] Domain available for registering: {}".format(domain.apex_domain))
            domain.available = True
        else:
            print("[i] Domain registered: {}".format(domain.apex_domain))
            domain.available = False
    return domains 
示例6
def run(self, domain, filename):

        if filename is not None:
            file = open(filename, 'a')
            print("File opened\n"
              "Getting information and writing it on the file..")
            whois = pformat(pythonwhois.get_whois(domain))
            file.write(whois)
            file.close()
        else:
            "Getting information.."
            pprint(pythonwhois.get_whois(domain)) 
示例7
def chk_whois(domain):
    #   *** .ca is not working, check more ***
    email = ns = createdate = expirationdate = updateddate = registrar = registrant = tel = ''
    w = dict(email=email, registrar=registrar, registrant=registrant, tel=tel, ns=ns, createdate=createdate, expirationdate=expirationdate, updateddate=updateddate)
    
    if chk_domain(domain):
        hostname, secondLD = chk_hostname(domain)
        try:
            #   find whois for second-level domain
            msg = 'parsing whois data of: %s ... ' % (secondLD)
            #logging.info(msg)
            ans = pythonwhois.get_whois(secondLD, True)
        except:
            return w
        if ans['contacts'].has_key('admin'):
            if ans['contacts']['admin'] is not None:
                if ans['contacts']['admin'].has_key('email'):
                    if ans['contacts']['admin']['email'] is not None:
                        email = ans['contacts']['admin']['email']
        if ans['contacts'].has_key('registrant'):
            if ans['contacts']['registrant'] is not None:
                if ans['contacts']['registrant'].has_key('name'):
                    if ans['contacts']['registrant']['name'] is not None:
                        registrant = ans['contacts']['registrant']['name']
                if ans['contacts']['registrant'].has_key('phone'):
                    if ans['contacts']['registrant']['phone'] is not None:
                        tel = ans['contacts']['registrant']['phone']
        if ans.has_key('registrar'):
            if ans['registrar'] is not None:
                registrar = ans['registrar']
            if type(ans['registrar']) is list:
                registrar = ans['registrar'][0]
        if ans.has_key('nameservers'):
            if ans['nameservers'] is not None:
                ns = ans['nameservers'][0]
        if ans.has_key('creation_date'):
            if ans['creation_date'] is not None:
                createdate = ans['creation_date']
        if ans.has_key('expiration_date'):
            if ans['expiration_date'] is not None:
                expirationdate = ans['expiration_date']
        if ans.has_key('updated_date'):
            if ans['updated_date'] is not None:
                updateddate = ans['updated_date']
        if createdate == '' and updateddate != '':
            createdate = updateddate
        w = dict(email=email, registrar=registrar.encode('utf-8'), registrant=registrant.encode('utf-8'), tel=tel, ns=ns, createdate=createdate, expirationdate=expirationdate, updateddate=updateddate)
    else:
        msg = '[*] no whois record: %s ...' % (domain)
        logging.info(msg)
    return w