当前位置: 首页>>代码示例>>Python>>正文


Python DNS.dnslookup方法代码示例

本文整理汇总了Python中DNS.dnslookup方法的典型用法代码示例。如果您正苦于以下问题:Python DNS.dnslookup方法的具体用法?Python DNS.dnslookup怎么用?Python DNS.dnslookup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DNS的用法示例。


在下文中一共展示了DNS.dnslookup方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: email_is_not_mit_mailing_list

# 需要导入模块: import DNS [as 别名]
# 或者: from DNS import dnslookup [as 别名]
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")
开发者ID:BakerWang,项目名称:zulip,代码行数:14,代码来源:forms.py

示例2: not_mit_mailing_list

# 需要导入模块: import DNS [as 别名]
# 或者: from DNS import dnslookup [as 别名]
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
开发者ID:wdaher,项目名称:zulip,代码行数:15,代码来源:forms.py

示例3: not_mit_mailing_list

# 需要导入模块: import DNS [as 别名]
# 或者: from DNS import dnslookup [as 别名]
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
开发者ID:galexrt,项目名称:zulip,代码行数:17,代码来源:forms.py

示例4: check_dkim

# 需要导入模块: import DNS [as 别名]
# 或者: from DNS import dnslookup [as 别名]
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
开发者ID:thefinn93,项目名称:email-setup-check,代码行数:28,代码来源:checks.py

示例5: dns_txt

# 需要导入模块: import DNS [as 别名]
# 或者: from DNS import dnslookup [as 别名]
def dns_txt(domain):
  try:
    resp = DNS.dnslookup(domain, 'TXT')
  except (DNS.ServerError, DNS.Base.TimeoutError) as err:
    print("{}: {}".format(domain, err.message), file=sys.stderr)
    return None

  response = []
  for r in resp:
    response.append(''.join(r))
  return response
开发者ID:0x9900,项目名称:whitelist,代码行数:13,代码来源:whitelist.py

示例6: BruteForce

# 需要导入模块: import DNS [as 别名]
# 或者: from DNS import dnslookup [as 别名]
def BruteForce(ParentDomain, verbose=False):
    """ Brute Force Forward DNS Lookups for some of the most common subdomain names. 
		These subdomain prefixes are obtained from the file specified in the argument """

    BruteForcePrefixes = open(str(utils.get_config()["brute_force_prefixes_file"]), "r")
    bruteforce_result_list = []  # Set of the domain names obtained by brute forcing

    for line in BruteForcePrefixes:

        CurrentName = (
            line.replace("\n", "") + "." + ParentDomain
        )  # Append the subdoamin prefix to the parent domain name [e.g. abc + google.com = abc.google.com]
        Display = "Current Name is: " + CurrentName

        if verbose:
            print "-" * len(Display)
            print Display

        try:
            IP = DNS.dnslookup(unicode(CurrentName, "utf-8"), qtype="A")[
                0
            ]  # Do a DNS Lookup for the current host name. #The current name will be a combination of the brute force prefix and the parent domain. E.g. - Sub=abc and Parent=xyz.com. So, current=abc.xyz.com
            bruteforce_result_list.append(CurrentName)
            if verbose:
                print "SUCCESS! IP/CNAME = " + IP
                display_text = (
                    "WebServerStatus = ON" if utils.is_port_open(IP, 80) == True else "WebServerStatus = OFF"
                )  # Test whether the destination IP's WebServer is ON. If it isn't, this domain isn't of any interest to us.
                utils.pretty_print(display_text, len(Display))
            else:
                print CurrentName
                # print " [Brute Force]"

        except DNS.Base.ServerError as e:
            display_text = (
                "\nThe DNS Server is Refusing requests. \nPlease use 8.8.8.8 and try again."
                if "REFUSED" in e.message
                else "Non-Existent Domain"
            )
            if verbose:
                utils.pretty_print(display_text, len(Display))
            continue

        except DNS.Base.TimeoutError:  # Handle the case where there's a DNS timeout
            if verbose:
                utils.pretty_print("Timeout", len(Display))
            continue

        except IndexError:  # This handles those (rare) cases where a valid DNS response is returned with no IP address (e.g. - 67.salesforce.com), because of which the variable index 0 of the array is non-existent and we thereforce cannot assign it to the variable 'IP'.
            if verbose:
                utils.pretty_print("Non-Existent Domain", len(Display))
            continue

    return bruteforce_result_list
开发者ID:balachandrannitish,项目名称:subdom-enum,代码行数:56,代码来源:bruteforce.py

示例7: lookup

# 需要导入模块: import DNS [as 别名]
# 或者: from DNS import dnslookup [as 别名]
def lookup(hostname, qtype=QTYPE_A):
    try:
        if HAVE_DNSPYTHON:
            arecs = []
            arequest = resolver.query(hostname, qtype)
            for rec in arequest:
                arecs.append(rec.to_text())
            return arecs

        elif HAVE_PYDNS:
            return DNS.dnslookup(hostname, qtype)

    except Exception:
        return None

    return None
开发者ID:ledgr,项目名称:postomaat,代码行数:18,代码来源:dnsquery.py

示例8: is_using_tor

# 需要导入模块: import DNS [as 别名]
# 或者: from DNS import dnslookup [as 别名]
def is_using_tor(clientIp, ELPort='80'):
    '''
    Find out if clientIp is a tor exit node following query type one.
    Inspired by https://svn.torproject.org/svn/check/trunk/cgi-bin/TorCheck.py
    Query Specification under https://gitweb.torproject.org/tordnsel.git/blob/HEAD:/doc/torel-design.txt
    See also https://check.torproject.org/
    '''

    DNS.DiscoverNameServers()

    # Put user ip in right format
    splitIp = clientIp.split('.')
    splitIp.reverse()
    ELExitNode = '.'.join(splitIp)

    # get beam's current ip address
    name = settings.ENV_SITE_MAPPING[settings.ENV][settings.SITE_USER]
    ElTarget = DNS.dnslookup(name, 'A')

    # ExitList DNS server we want to query
    ELHost = 'ip-port.exitlist.torproject.org'

    # Prepare the question as an A record (i.e. a 32-bit IPv4 address) request
    ELQuestion = ELExitNode + "." + ELPort + "." + ElTarget[1] + "." + ELHost
    request = DNS.DnsRequest(name=ELQuestion, qtype='A', timeout=settings.TOR_TIMEOUT)

    # Ask the question and load the data into our answer
    try:
        answer = request.req()
    except DNS.DNSError as e:
        log_error('ERROR Tor - Failed to query ip address: {}'.format(e[0]))
        return False

    # Parse the answer and decide if it's allowing exits
    # 127.0.0.2 is an exit and NXDOMAIN is not
    if answer.header['status'] == 'NXDOMAIN':
        return False
    else:
        # unexpected response
        if not answer.answers:
            log_error('ERROR Tor - Query returned unexpected response')
            return False
        for a in answer.answers:
            if a['data'] != '127.0.0.2':
                return False
        return True
开发者ID:fbenke,项目名称:BeamRemit,代码行数:48,代码来源:ip_blocking.py

示例9: compute_mit_user_fullname

# 需要导入模块: import DNS [as 别名]
# 或者: from DNS import dnslookup [as 别名]
def compute_mit_user_fullname(email: str) -> str:
    try:
        # Input is either e.g. [email protected] or user|[email protected]
        match_user = re.match(r'^([a-zA-Z0-9_.-]+)(\|.+)[email protected]\.edu$', email.lower())
        if match_user and match_user.group(2) is None:
            answer = DNS.dnslookup(
                "%s.passwd.ns.athena.mit.edu" % (match_user.group(1),),
                DNS.Type.TXT)
            hesiod_name = answer[0][0].split(':')[4].split(',')[0].strip()
            if hesiod_name != "":
                return hesiod_name
        elif match_user:
            return match_user.group(1).lower() + "@" + match_user.group(2).upper()[1:]
    except DNS.Base.ServerError:
        pass
    except Exception:
        print("Error getting fullname for %s:" % (email,))
        traceback.print_exc()
    return email.lower()
开发者ID:BakerWang,项目名称:zulip,代码行数:21,代码来源:zephyr.py

示例10: getEntry

# 需要导入模块: import DNS [as 别名]
# 或者: from DNS import dnslookup [as 别名]
 def getEntry(self,dominio,type="A",timeout = 5,dnsservers = ['8.8.8.8', '8.8.4.4']):
     try:
         if (dominio != ""):
             DNS.defaults['server'] = dnsservers
             DNS.defaults['timeout'] = timeout
             resul = DNS.dnslookup(dominio, type)
             if (len(resul) > 0):
                 return resul[0]
             else:
                 return -1
         else:
             return -1
     except DNS.ServerError as e:
         if e.rcode == 3:
             return -1
         else:
             return -2
     except Exception as e:
         return -2
开发者ID:ggusoft,项目名称:inforfinder,代码行数:21,代码来源:bingchecker.py

示例11: check

# 需要导入模块: import DNS [as 别名]
# 或者: from DNS import dnslookup [as 别名]
  def check(self, instance):

    # if DNS domain for eureka instance not specified -- skip instance
    if 'domain' not in instance:
      self.log.info('Skipping instance, no domain found.')
      return

    # Parsing eureka instance details, setting defaults if necessary
    protocol = instance.get('protocol', 'http')
    port = int(instance.get('port', 8080))
    context = instance.get('context','/eureka/v2')
    region = instance.get('region', 'us-east-1')
    timeout = float(instance.get('timeout', 5))
    essential_applications = instance.get('essential_applications', [])
    tags = instance.get('tags', [])

    try:
      txt_records = DNS.dnslookup('txt.' + region + '.' + instance['domain'],'txt')

      # We take first TXT record here
      if len(txt_records):
        eureka_nodes = txt_records[0]
      else:
        eureka_nodes = []
    except DNS.ServerError as e:
      self.gauge('eureka.nodes_num', 0, tags=tags)
      return

    # Number of nodes found in Eureka dns setup
    self.gauge('eureka.nodes_num', len(eureka_nodes), tags=tags)

    # Check every node found in dns setup
    for eureka_node_name in eureka_nodes:
      eureka_node = {
        'name': eureka_node_name,
        'protocol': protocol,
        'port': port,
        'context': context,
        'timeout': timeout,
        'essential_applications': essential_applications
      }
      self.check_eureka_node(eureka_node, tags=tags)
开发者ID:Smartling,项目名称:datadog-eureka-health,代码行数:44,代码来源:eurekahealth.py

示例12: check_dmarc

# 需要导入模块: import DNS [as 别名]
# 或者: from DNS import dnslookup [as 别名]
def check_dmarc(domain, dmarc_record):
    """Check that the proper DMARC records are in place for a given domain."""
    results = {
        'test': 'dmarc',
        'passed': None,
        'records': [{'domain': '_dmarc.%s' % domain, 'type': 'TXT', 'value': dmarc_record}],
        'messages': ['This test is kinda crappy and may yield false negatives.']
    }
    try:
        actual_records = DNS.dnslookup('_dmarc.%s' % domain, 'TXT')
    except DNS.Base.ServerError:
        actual_records = []
    for record in actual_records:
        current_record = record[0].decode()
        if current_record == dmarc_record and results['passed'] is not False:
            results['passed'] = True
        else:
            results['passed'] = False
    if len(actual_records) == 0:
        results['messages'].append('No DMARC records found!')
        results['passed'] = False
    return results
开发者ID:thefinn93,项目名称:email-setup-check,代码行数:24,代码来源:checks.py

示例13: check_mx

# 需要导入模块: import DNS [as 别名]
# 或者: from DNS import dnslookup [as 别名]
def check_mx(domain, servers):
    """Check that the proper MX records are in place for a given domain."""
    results = {
        'test': 'mx',
        'passed': None,
        'records': [],
        'messages': []
    }
    for server in servers:
        results['records'].append({'domain': domain, 'type': 'MX', 'value': server})
    actual_records = DNS.dnslookup(domain, 'MX')
    records = []
    for record in actual_records:
        records.append(record[1])
    for record in servers:
        if record in records:
            if results['passed'] is not False:
                results['passed'] = True
            results['messages'].append('MX record for %s found' % record)
        else:
            results['passed'] = False
    if len(actual_records) == 0:
        results['messages'].append('No MX records found!')
    return results
开发者ID:thefinn93,项目名称:email-setup-check,代码行数:26,代码来源:checks.py

示例14:

# 需要导入模块: import DNS [as 别名]
# 或者: from DNS import dnslookup [as 别名]
import DNS

DNS.dnslookup("boards.ie",'TXT')
开发者ID:Dankoozie,项目名称:puggsy,代码行数:5,代码来源:transport_dns.py

示例15: to_ip

# 需要导入模块: import DNS [as 别名]
# 或者: from DNS import dnslookup [as 别名]
 def to_ip(value):
     try:
         value = DNS.dnslookup('www.google.com', 'A')
     except:
         value = None
     return value
开发者ID:aaronkaplan,项目名称:intelmq-beta,代码行数:8,代码来源:harmonization.py


注:本文中的DNS.dnslookup方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。