本文整理汇总了Python中DNS类的典型用法代码示例。如果您正苦于以下问题:Python DNS类的具体用法?Python DNS怎么用?Python DNS使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DNS类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __main
def __main():
t0 = time.time()
# Login to the peer tracker and get the current client IPs
clients = DNS.login(TRACKER)
node = nodeThread.node()
node.start() #starts listening
# Peer and relay with OR1
messenger.sendPeerRequest(RELAYS[0])
messenger.sendRelayRequest(RELAYS[0])
# Relay with OR2 through OR1
messenger.onionRouteMessage([RELAYS[0], RELAYS[1]], message.RELAY_SYN)
# Relay with OR3 through OR1,OR2
messenger.onionRouteMessage([RELAYS[0], RELAYS[1], RELAYS[2]], message.RELAY_SYN)
# Register nickname with NP through OR1, OR2, OR3
messenger.onionRouteMessage([RELAYS[0], RELAYS[1], RELAYS[2], RELAYS[3]], message.PROXY_SYN + NICK)
time.sleep(3)
while (TARGET not in clients):
t1 = time.time()
if (t1-t0) >= TIMEOUT:
clients = DNS.login(TRACKER)
t0 = t1
# Send Bob a message
messenger.onionRouteMessage([RELAYS[0], RELAYS[1], RELAYS[2], TARGET_NICKNAME_PROXY], message.TO_NICK + TARGET_NICK + message.SEPARATOR + "Testing")
time.sleep(TIMEOUT)
示例2: __main
def __main():
t0 = time.time()
# Login to the peer tracker and get the current client IPs
clients = DNS.login(TRACKER)
node = nodeThread.node()
node.start() #starts listening
targetAddress = TARGET
#Peer and relay with OR1
messenger.sendPeerRequest(RELAYS[NUM_OF_RELAYS-1])
messenger.sendRelayRequest(RELAYS[NUM_OF_RELAYS-1])
# Relay with OR2 through OR1
messenger.onionRouteMessage([RELAYS[NUM_OF_RELAYS-1], RELAYS[NUM_OF_RELAYS-2]], message.RELAY_SYN)
# Relay with OR3 through OR1,OR2
messenger.onionRouteMessage([RELAYS[NUM_OF_RELAYS-1], RELAYS[NUM_OF_RELAYS-2], RELAYS[NUM_OF_RELAYS-3]], message.RELAY_SYN)
# Register nickname with NP through OR1, OR2, OR3
messenger.onionRouteMessage([RELAYS[NUM_OF_RELAYS-1], RELAYS[NUM_OF_RELAYS-2], RELAYS[NUM_OF_RELAYS-3], RELAYS[NUM_OF_RELAYS-4]], message.PROXY_SYN + NICK)
#Be logged in and keep nodeThread up
while 1:
t1 = time.time()
if (t1-t0) >= TIMEOUT:
clients = DNS.login(TRACKER)
t0 = t1
示例3: email_is_not_mit_mailing_list
def email_is_not_mit_mailing_list(email: str) -> None:
"""Prevent MIT mailing lists from signing up for Zulip"""
if "@mit.edu" in email:
username = email.rsplit("@", 1)[0]
# Check whether the user exists and can get mail.
try:
DNS.dnslookup("%s.pobox.ns.athena.mit.edu" % username, DNS.Type.TXT)
except DNS.Base.ServerError as e:
if e.rcode == DNS.Status.NXDOMAIN:
raise ValidationError(mark_safe(MIT_VALIDATION_ERROR))
else:
raise AssertionError("Unexpected DNS error")
示例4: not_mit_mailing_list
def not_mit_mailing_list(value):
# I don't want ec-discuss signed up for Zulip
if "@mit.edu" in value:
username = value.rsplit("@", 1)[0]
# Check whether the user exists and can get mail.
try:
DNS.dnslookup("%s.pobox.ns.athena.mit.edu" % username, DNS.Type.TXT)
return True
except DNS.Base.ServerError, e:
if e.rcode == DNS.Status.NXDOMAIN:
raise ValidationError(mark_safe(u'That user does not exist at MIT or is a <a href="https://ist.mit.edu/email-lists">mailing list</a>. If you want to sign up an alias for Zulip, <a href="mailto:[email protected]">contact us</a>.'))
else:
raise
示例5: not_mit_mailing_list
def not_mit_mailing_list(value):
# type: (str) -> bool
"""Prevent MIT mailing lists from signing up for Zulip"""
if "@mit.edu" in value:
username = value.rsplit("@", 1)[0]
# Check whether the user exists and can get mail.
try:
DNS.dnslookup("%s.pobox.ns.athena.mit.edu" % username, DNS.Type.TXT)
return True
except DNS.Base.ServerError as e:
if e.rcode == DNS.Status.NXDOMAIN:
raise ValidationError(mark_safe(MIT_VALIDATION_ERROR))
else:
raise
return True
示例6: __main
def __main():
t0 = time.time()
clients = DNS.login(TRACKER)
#Be logged in
while 1:
t1 = time.time()
if (t1-t0) >= TIMEOUT:
clients = DNS.login(TRACKER)
t0 = t1
for client in clients:
if client not in PEERS:
PEERS.append(client)
messenger.sendPeerRequest(client)
示例7: get_mx_ip
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
示例8: run
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()
示例9: validate_email
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
示例10: check_dkim
def check_dkim(domain, selector, folder):
"""Test the DKIM records for the given domain."""
correct_record = open(os.path.join(folder, domain, '%s.txt' % selector)).read().split('"')[1]
txt_domain = '%s._domainkey.%s' % (selector, domain)
results = {
'test': 'dkim',
'passed': False,
'records': [{'domain': txt_domain, 'type': 'TXT', 'value': correct_record}],
'messages': []
}
try:
actual_records = DNS.dnslookup(txt_domain, 'TXT')
if len(actual_records) == 0:
results['messages'].append("This test probably is yeilding a false negative.")
except DNS.Base.ServerError:
actual_records = []
results['messages'].append('No DKIM records found (for selector %s)' % selector)
for record in actual_records:
current_record = record[0].decode()
if current_record == correct_record:
if not results['passed']:
results['passed'] = True
results['messages'].append('Correct DKIM record found at %s' % txt_domain)
else:
results['messages'].append("%s found instead" % current_record)
return results
示例11: mxlookup
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
示例12: query_mx
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]
示例13: validate_email
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
示例14: get_mx_for_domain
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
示例15: DNSMXQuery
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])