本文整理汇总了Python中DNS.mxlookup方法的典型用法代码示例。如果您正苦于以下问题:Python DNS.mxlookup方法的具体用法?Python DNS.mxlookup怎么用?Python DNS.mxlookup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DNS
的用法示例。
在下文中一共展示了DNS.mxlookup方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: import DNS [as 别名]
# 或者: from DNS import mxlookup [as 别名]
def run(self):
if not self.options.get('user', None):
logging.error(
'Need to include --user to report who the submissions is from.')
return
domain = self.options['rcpt'].split('@')[-1]
mx = DNS.mxlookup(domain)
if not mx:
logging.error("Can't get an MX for %s" % (domain,))
return
server = smtplib.SMTP(mx[0][1])
text = email.mime.text.MIMEText('Package submission from %s for %s' % (
self.options['user'],self.project.metadata['name']))
btapp = email.mime.application.MIMEApplication(
open(os.path.join('dist', '%s.btapp' % (
self.project.metadata['name'],)), 'rb').read(),
'zip', name='%s.btapp' % self.project.metadata['name'])
msg = email.mime.base.MIMEBase('multipart', 'mixed')
msg.add_header('Subject', 'Submission of %s for %s' % (
self.project.metadata['name'], self.options['user']))
msg.add_header('From', self.options['user'])
msg.add_header('To', self.options['rcpt'])
msg.attach(text)
msg.attach(btapp)
server.sendmail(self.options['user'], self.options['rcpt'],
str(msg))
server.quit()
示例2: mxlookup
# 需要导入模块: import DNS [as 别名]
# 或者: from DNS import mxlookup [as 别名]
def mxlookup(domain):
try:
if HAVE_DNSPYTHON:
mxrecs = []
mxrequest = resolver.query(domain, 'MX')
for rec in mxrequest:
mxrecs.append(rec.to_text())
mxrecs.sort() #automatically sorts by priority
return [x.split(None,1)[-1] for x in mxrecs]
elif HAVE_PYDNS:
mxrecs=[]
mxrequest = DNS.mxlookup(domain)
for dataset in mxrequest:
if type(dataset) == tuple:
mxrecs.append(dataset)
mxrecs.sort() #automatically sorts by priority
return [x[1] for x in mxrecs]
except Exception:
pass
#TODO: other dns libraries?
return None
示例3: query_mx
# 需要导入模块: import DNS [as 别名]
# 或者: from DNS import mxlookup [as 别名]
def query_mx(domain):
if domain not in mx_records:
mx_hosts = DNS.mxlookup(domain)
mx_records[domain] = mx_hosts
if not mx_hosts:
print "invalid domain: ", domain
return mx_records[domain]
示例4: get_mx_ip
# 需要导入模块: import DNS [as 别名]
# 或者: from DNS import mxlookup [as 别名]
def get_mx_ip(hostname):
try:
return MX_DNS_CACHE[hostname]
except KeyError:
mx_hosts = DNS.mxlookup(hostname)
MX_DNS_CACHE[hostname] = mx_hosts
return mx_hosts
示例5: validate_email
# 需要导入模块: import DNS [as 别名]
# 或者: from DNS import mxlookup [as 别名]
def validate_email(email, check_mx=False,verify=False):
"""Indicate whether the given string is a valid email address
according to the 'addr-spec' portion of RFC 2822 (see section
3.4.1). Parts of the spec that are marked obsolete are *not*
included in this test, and certain arcane constructions that
depend on circular definitions in the spec may not pass, but in
general this should correctly identify any email address likely
to be in use as of 2011."""
try:
assert re.match(VALID_ADDRESS_REGEXP, email) is not None
check_mx |= verify
if check_mx:
if not DNS: raise Exception('For check the mx records or check if the email exists you must have installed pyDNS python package')
DNS.DiscoverNameServers()
hostname = email[email.find('@')+1:]
mx_hosts = DNS.mxlookup(hostname)
for mx in mx_hosts:
try:
smtp = smtplib.SMTP()
smtp.connect(mx[1])
if not verify: return True
status, _ = smtp.helo()
if status != 250: continue
smtp.mail('')
status, _ = smtp.rcpt(email)
if status != 250: return False
break
except smtplib.SMTPServerDisconnected: #Server not permits verify user
break
except smtplib.SMTPConnectError:
continue
except (AssertionError, ServerError):
return False
return True
示例6: validate_email
# 需要导入模块: import DNS [as 别名]
# 或者: from DNS import mxlookup [as 别名]
def validate_email(email, check_mx=False, verify=False, debug=False):
"""Indicate whether the given string is a valid email address
according to the 'addr-spec' portion of RFC 2822 (see section
3.4.1). Parts of the spec that are marked obsolete are *not*
included in this test, and certain arcane constructions that
depend on circular definitions in the spec may not pass, but in
general this should correctly identify any email address likely
to be in use as of 2011."""
if debug:
logger = logging.getLogger('validate_email')
logger.setLevel(logging.DEBUG)
else:
logger = None
try:
assert re.match(VALID_ADDRESS_REGEXP, email) is not None
check_mx |= verify
if check_mx:
if not DNS:
raise Exception('For check the mx records or check if the email exists you must '
'have installed pyDNS python package')
DNS.DiscoverNameServers()
hostname = email[email.find('@') + 1:]
mx_hosts = DNS.mxlookup(hostname)
for mx in mx_hosts:
try:
smtp = smtplib.SMTP()
smtp.connect(mx[1])
if not verify:
smtp.quit()
return True
status, _ = smtp.helo()
if status != 250:
smtp.quit()
if debug:
logger.debug(u'%s answer: %s - %s', mx[1], status, _)
continue
smtp.mail('')
status, _ = smtp.rcpt(email)
if status == 250:
smtp.quit()
return True
if debug:
logger.debug(u'%s answer: %s - %s', mx[1], status, _)
smtp.quit()
except smtplib.SMTPServerDisconnected: # Server not permits verify user
if debug:
logger.debug(u'%s disconected.', mx[1])
except smtplib.SMTPConnectError:
if debug:
logger.debug(u'Unable to connect to %s.', mx[1])
return None
except AssertionError:
return False
except (ServerError, socket.error) as e:
if debug:
logger.debug('ServerError or socket.error exception raised (%s).', e)
return None
return True
示例7: get_mx_for_domain
# 需要导入模块: import DNS [as 别名]
# 或者: from DNS import mxlookup [as 别名]
def get_mx_for_domain(domain):
try:
mx_list = DNS.mxlookup(domain)
best_mx_ip = sorted(mx_list)[0][1]
except:
best_mx_ip = None
return best_mx_ip
示例8: read
# 需要导入模块: import DNS [as 别名]
# 或者: from DNS import mxlookup [as 别名]
def read(self,request,emailadress):
emailadress=emailadress.split("@")
DNS.DiscoverNameServers()
mxhosts=DNS.mxlookup(emailadress[1])
if(mxhosts):
return "dogru"
else:
return "yanlis"
示例9: DNSMXQuery
# 需要导入模块: import DNS [as 别名]
# 或者: from DNS import mxlookup [as 别名]
def DNSMXQuery(hostname):
r = DNS.DnsRequest(qtype="MX")
mx_hosts = DNS.mxlookup(hostname)
if len(mx_hosts) == 0:
print "0 MX server found\n"
else:
for mx in mx_hosts:
print mx[1] + "\t " + getIp(mx[1])
示例10: get_mx_ip
# 需要导入模块: import DNS [as 别名]
# 或者: from DNS import mxlookup [as 别名]
def get_mx_ip(hostname):
if hostname not in MX_DNS_CACHE:
try:
MX_DNS_CACHE[hostname] = DNS.mxlookup(hostname)
except ServerError, e:
if e.rcode == 3: # NXDOMAIN (Non-Existent Domain)
MX_DNS_CACHE[hostname] = None
else:
raise
示例11: testDnsRequestMX
# 需要导入模块: import DNS [as 别名]
# 或者: from DNS import mxlookup [as 别名]
def testDnsRequestMX(self):
dnsobj = DNS.DnsRequest('ietf.org')
mx_response = dnsobj.qry(qtype='MX')
self.assertTrue(mx_response.answers[0])
# is hard coding a remote address a good idea?
# I think it's unavoidable. - sk
self.assertEqual(mx_response.answers[0]['data'], (0, 'mail.ietf.org'))
m = DNS.mxlookup('ietf.org')
self.assertEqual(mx_response.answers[0]['data'], m[0])
示例12: get_mx_ip
# 需要导入模块: import DNS [as 别名]
# 或者: from DNS import mxlookup [as 别名]
def get_mx_ip(hostname):
if hostname not in MX_DNS_CACHE:
try:
MX_DNS_CACHE[hostname] = DNS.mxlookup(hostname)
except ServerError as e:
if e.rcode == 3 or e.rcode == 2: # NXDOMAIN (Non-Existent Domain) or SERVFAIL
MX_DNS_CACHE[hostname] = None
else:
raise
return MX_DNS_CACHE[hostname]
示例13: get_mx_ip
# 需要导入模块: import DNS [as 别名]
# 或者: from DNS import mxlookup [as 别名]
def get_mx_ip(self, hostname):
if hostname not in self.MX_DNS_CACHE:
try:
self.MX_DNS_CACHE[hostname] = DNS.mxlookup(hostname)
except ServerError as e:
if e.rcode == 3: # NXDOMAIN (Non-Existent Domain)
self.MX_DNS_CACHE[hostname] = None
else:
raise
return self.MX_DNS_CACHE[hostname]
示例14: resolve_relay_host
# 需要导入模块: import DNS [as 别名]
# 或者: from DNS import mxlookup [as 别名]
def resolve_relay_host(self, To):
import DNS
address, target_host = To.split('@')
mx_hosts = DNS.mxlookup(target_host)
if not mx_hosts:
logging.debug("Domain %r does not have an MX record, using %r instead.", target_host, target_host)
return target_host
else:
logging.debug("Delivering to MX record %r for target %r", mx_hosts[0], target_host)
return mx_hosts[0][1]
示例15: get_mx_hosts
# 需要导入模块: import DNS [as 别名]
# 或者: from DNS import mxlookup [as 别名]
def get_mx_hosts(self, mail):
domain = mail.split('@')[1]
if domain != self.domain or not self.mx_hosts:
self.domain = domain
try:
self.mx_hosts = DNS.mxlookup(self.domain)
except DNS.Base.ServerError:
self.logger.error('It seems this domain has no MX entry: %s' % self.domain)
sys.exit(1)
self.logger.debug('MX hosts for domain %s:' % self.domain)
for priority, mail_server in self.mx_hosts:
self.logger.debug(" * %s %s" % (priority, mail_server))
return self.mx_hosts