本文整理汇总了Python中whois.whois函数的典型用法代码示例。如果您正苦于以下问题:Python whois函数的具体用法?Python whois怎么用?Python whois使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了whois函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: whois_lookup
def whois_lookup(url):
try:
whois.whois(url)
sys.stderr.write('unavailable domain: %s\n' % (url))
sys.stderr.flush()
except Exception:
print('available domain: %s' % (url))
示例2: run
def run(self, query, cmd, *args):
# rip out newlines and gibberish
query = query.strip()
# replace the misp-style de-fanging
query = query.replace("[", "")
query = query.replace("]", "")
parsed_uri = urlparse(query)
# if it's an IP address
try:
if parsed_uri.netloc == '' and re.match('^\d{,3}\.\d{,3}\.\d{,3}\.\d{,3}$', query):
self.logger.debug("whois on ip '{}'".format(query))
w = whois.whois(query)
elif parsed_uri.netloc == '' and parsed_uri.path != '':
self.logger.debug("whois on domain '{}'".format(parsed_uri.path))
w = whois.whois(parsed_uri.path)
else:
self.logger.debug("whois on domain '{}'".format(parsed_uri.netloc))
w = whois.whois(parsed_uri.netloc)
except whois.parser.PywhoisError as e:
return (False, {'error' : e})
if w.get('status', False) == False:
return (False, {'error' : "No result returned"})
result = clean_dict(w)
result['text'] = w.text.replace(">>> ", "--- ").replace(" <<<", " ---")
return (True, result)
示例3: is_available
def is_available(self, domain):
''' Blindly grabbing PywhoisError isn't ideal but works '''
try:
whois(domain)
return False
except PywhoisError:
return True
示例4: whois_validate_domain
def whois_validate_domain(value):
'''
Check that this is a domain according to whois
'''
try:
whois.whois(str(value))
except PywhoisError:
msg = _('%(domain)s does not seem to be a valid domain name')
raise ValidationError(msg % {'domain': value})
示例5: whois_handler
def whois_handler(bot, update, args):
chat_id = update.message.chat_id
domain = args[0] if len(args) > 0 else None
whois_response = whois.whois(domain) if whois.whois(domain) else None
if whois_response is None:
bot.sendMessage(chat_id, text="Sorry, I can't retrieve whois information about: {}.".format(domain))
return
bot.sendMessage(chat_id, text='Whois: {}'.format(whois_response.text))
示例6: whois_validate_domain
def whois_validate_domain(value):
"""
Check that this is a domain according to whois
"""
try:
whois.whois(value)
except PywhoisError:
msg = _("%(domain)s does not seem to be a valid domain name")
raise ValidationError(msg % {"domain": value})
示例7: whois_lookup
def whois_lookup(url):
url_parse = urlparse(url)
new_url = str(url_parse.scheme) + "://" + str(url_parse.netloc)
try:
whois.whois(new_url)
return 1
except:
return -1
示例8: getISP
def getISP(ip):
tmp=gi.record_by_addr(ip)
if ip in torexits:
return tmp['city'], tmp['country_name'], "TOR"
if tmp:
return tmp['city'], tmp['country_name'], whois(ip)[-1]
tmp=whois(ip)
if tmp:
return 'unknown', 'unknown', tmp[-1]
return 'unknown', 'unknown', ip
示例9: run_whois
def run_whois(self,domain):
"""Perform a WHOIS lookup for the provided target domain. The WHOIS results are returned
as a dictionary.
This can fail, usually if the domain is protected by a WHOIS privacy service or the
registrar has their own WHOIS service.
Parameters:
domain The domain to use for the WHOIS query
"""
try:
who = whois.whois(domain)
results = {}
# Check if info was returned before proceeding because sometimes records are protected
if who.registrar:
results['domain_name'] = who.domain_name
results['registrar'] = who.registrar
results['expiration_date'] = who.expiration_date
results['registrant'] = who.name
results['org'] = who.org
results['admin_email'] = who.emails[0]
results['tech_email'] = who.emails[1]
results['address'] = "{}, {}{}, {}, {}".format(who.address,who.city,who.zipcode,who.state,who.country)
results['dnssec'] = who.dnssec
else:
click.secho("[*] WHOIS record for {} came back empty. You might try looking at dnsstuff.com.".format(domain),fg="yellow")
return results
except Exception as error:
click.secho("[!] The WHOIS lookup for {} failed!".format(domain),fg="red")
click.secho("L.. Details: {}".format(error),fg="red")
示例10: domainify
def domainify():
"""Returns a random domain where the last characters form a TLD"""
results = open('results','r')
domains = []
try:
while True:
domains.append(pickle.load(results))
except EOFError:
while True:
pick = domains[random.randint(0, (len(domains))-1)]
print(pick[0])
definition = find(pick[0][0])
if definition:
results = []
for (word,tld) in pick:
try:
domain = word[:len(word)-len(tld)] + '.' + tld
if whois.whois(domain)["expiration_date"]:
results.append({'domain':domain, 'definition':definition})
except (UnboundLocalError, KeyError):
pass
except whois.parser.PywhoisError: # this isn't 100% accurate
results.append({'domain':domain, 'definition':definition})
if len(results)>0:
return results[random.randint(0, (len(results))-1)]
示例11: checkargs
def checkargs():
fqdn = sys.argv[1]
image = sys.argv[2]
flavor = sys.argv[3]
try:
img = cs.images.get(image)
print "Good news, we found a valid image, continuing.."
except:
print "Sorry, your image was not found in the image list. Please try again."
quit()
try:
int(flavor)
except:
print "Your flavor input was not numeric. Please try again."
quit()
try:
cs.flavors.get(flavor)
print "Valid flavor, still continuing"
except:
print "Your flavor is out of range. Please try again."
quit()
try:
w = whois.whois(fqdn)
print "Seems like a valid FQDN, let's keep rolling.."
except:
print
print "This domain isn't a FQDN, please choose one that is. Quitting now."
quit()
create(fqdn, image, img, flavor)
示例12: check_domain_available
def check_domain_available(self,domain_name):
# print( dir(whois))
# domain = "esencia.in"
w = whois(domain_name)
t = w.query(False)
p = parser.Parser(domain_name, t[1], t[0], True)
try:
# print( p.text)
result=p.parse()
print("######################")
print(domain_name)
if "NotFound" not in result:
print ("Registrar:",list(result['Registrar']))
print ("RegistrantID:",list(result['RegistrantID']))
print ("CreationDate:",list(result['CreationDate']))
print ("ExpirationDate",list(result['ExpirationDate']))
print ("UpdateDate",list(result['UpdatedDate']))
print ("RegistrantEmail:",list(result['RegistrantEmail']))
except Exception as e:
print(str(e))
示例13: main
def main():
opts, args = options.parse_args()
if len(args) < 1:
options.print_help()
return
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
site=args[0]
s.connect((args[0], opts.port))
s.send(hello)
while True:
typ, ver, pay = recvmsg(s)
if typ == None:
return
# Look for server hello done message.
if typ == 22 and ord(pay[0]) == 0x0E:
break
s.send(hb)
b = hit_hb(s)
if b == False:
print site+" is not vulnerable"
else:
print site+" is VULNERABLE!"
w = whois.whois(site)
for x in range(0, len(w.emails)):
sendmail(w.emails[x])
示例14: get_whois
def get_whois(domain):
global COUNT
host = random.choice([USE_WHOIS_CMD, random.choice(HOST)])
logging.info("Retrieving whois of domain '%s' by using '%s'." % (domain, host))
if COUNT == 10:
logging.warn("Whoiser thread is sleeping for 2 seconds.")
time.sleep(2)
host = USE_WHOIS_CMD
COUNT = 0
w = None
try:
w = whois.whois(domain, host)
except Exception as e:
logging.error("PyWhois Exception: %s" % e)
if w is None:
COUNT += 1
logging.error("FAIL Retrieve whois of domain '%s' fail." % domain)
return None
#: 没有邮箱直接判定为查询失败
elif w.emails is not None:
logging.debug("SUCCESS Retrieve whois of domain '%s'." % domain)
return w
else:
COUNT += 1
logging.error("FAIL Retrieve whois of domain '%s' fail." % domain)
return None
示例15: __get_whois_record
def __get_whois_record(self, domain):
try:
record = whois.whois(domain)
except Exception, e:
sys.stderr.write('The whois lookup for the domain: ' + domain + ' failed for the following reason:\n\n')
sys.stderr.write(e + "\n")
return None