Fetch a DNS record
766267
def get_record(self, dns_record_type, host):
        """"""
        record_list = self._entries
        for record in record_list:
            if record._record_type == dns_record_type \
                    and record.host == host:
                return record
        return False
1346469
public static dnssuffix[] get(nitro_service service) throws Exception{
		dnssuffix obj = new dnssuffix();
		dnssuffix[] response = (dnssuffix[])obj.get_resources(service);
		return response;
	}
589283
def get_asn_dns(self):
        

        try:

            log.debug('ASN query for {0}'.format(self.dns_zone))
            data = self.dns_resolver.query(self.dns_zone, 'TXT')
            return list(data)

        except (dns.resolver.NXDOMAIN, dns.resolver.NoNameservers,
                dns.resolver.NoAnswer, dns.exception.Timeout) as e:

            raise ASNLookupError(
                'ASN lookup failed (DNS {0}) for {1}.'.format(
                    e.__class__.__name__, self.address_str)
            )

        except:  # pragma: no cover

            raise ASNLookupError(
                'ASN lookup failed for {0}.'.format(self.address_str)
            )
531516
def fetch(self):
        
        api = self.doapi_manager
        return api._domain(api.request(self.url)["domain"])
554997
def domain_records(self, domain_id):
        
        json = self.request('/domains/%s/records' % domain_id, method='GET')
        status = json.get('status')
        if status == 'OK':
            records_json = json.get('records', [])
            records = [Record.from_json(record) for record in records_json]
            return records
        else:
            message = json.get('message')
            raise DOPException('[%s]: %s' % (status, message))
778498
def parse_get(prs, conn):
    
    prs_get = prs.add_parser(
        'get', help='retrieve all zones or records with a specific zone')
    prs_get.add_argument('--domain', action='store',
                         help='specify domain FQDN')
    conn_options(prs_get, conn)
    set_option(prs_get, 'search')
    prs_get.set_defaults(func=get)
77292
def rm_dns(ip, interface='Local Area Connection'):
    '''
    
    '''
    cmd = ['netsh', 'interface', 'ip', 'delete', 'dns', interface, ip, 'validate=no']
    return __salt__['cmd.retcode'](cmd, python_shell=False) == 0
248789
def cli(env, identifier, a_record, aaaa_record, ptr, ttl):
    """"""

    items = ['id',
             'globalIdentifier',
             'fullyQualifiedDomainName',
             'hostname',
             'domain',
             'primaryBackendIpAddress',
             'primaryIpAddress',
             '''primaryNetworkComponent[
                id, primaryIpAddress,
                primaryVersion6IpAddressRecord[ipAddress]
             ]''']
    mask = "mask[%s]" % ','.join(items)
    dns = SoftLayer.DNSManager(env.client)
    vsi = SoftLayer.VSManager(env.client)

    vs_id = helpers.resolve_id(vsi.resolve_ids, identifier, 'VS')
    instance = vsi.get_instance(vs_id, mask=mask)
    zone_id = helpers.resolve_id(dns.resolve_ids,
                                 instance['domain'],
                                 name='zone')

    def sync_a_record():
        """Sync A record."""
        records = dns.get_records(zone_id,
                                  host=instance['hostname'],
                                  record_type='a')
        if not records:
            # don't have a record, lets add one to the base zone
            dns.create_record(zone['id'],
                              instance['hostname'],
                              'a',
                              instance['primaryIpAddress'],
                              ttl=ttl)
        else:
            if len(records) != 1:
                raise exceptions.CLIAbort("Aborting A record sync, found "
                                          "%d A record exists!" % len(records))
            rec = records[0]
            rec['data'] = instance['primaryIpAddress']
            rec['ttl'] = ttl
            dns.edit_record(rec)

    def sync_aaaa_record():
        """Sync AAAA record."""
        records = dns.get_records(zone_id,
                                  host=instance['hostname'],
                                  record_type='aaaa')
        try:
            # done this way to stay within 80 character lines
            component = instance['primaryNetworkComponent']
            record = component['primaryVersion6IpAddressRecord']
            ip_address = record['ipAddress']
        except KeyError:
            raise exceptions.CLIAbort("%s does not have an ipv6 address"
                                      % instance['fullyQualifiedDomainName'])

        if not records:
            # don't have a record, lets add one to the base zone
            dns.create_record(zone['id'],
                              instance['hostname'],
                              'aaaa',
                              ip_address,
                              ttl=ttl)
        else:
            if len(records) != 1:
                raise exceptions.CLIAbort("Aborting A record sync, found "
                                          "%d A record exists!" % len(records))
            rec = records[0]
            rec['data'] = ip_address
            rec['ttl'] = ttl
            dns.edit_record(rec)

    def sync_ptr_record():
        """Sync PTR record."""
        host_rec = instance['primaryIpAddress'].split('.')[-1]
        ptr_domains = (env.client['Virtual_Guest']
                       .getReverseDomainRecords(id=instance['id'])[0])
        edit_ptr = None
        for ptr in ptr_domains['resourceRecords']:
            if ptr['host'] == host_rec:
                ptr['ttl'] = ttl
                edit_ptr = ptr
                break

        if edit_ptr:
            edit_ptr['data'] = instance['fullyQualifiedDomainName']
            dns.edit_record(edit_ptr)
        else:
            dns.create_record(ptr_domains['id'],
                              host_rec,
                              'ptr',
                              instance['fullyQualifiedDomainName'],
                              ttl=ttl)

    if not instance['primaryIpAddress']:
        raise exceptions.CLIAbort('No primary IP address associated with '
                                  'this VS')

    zone = dns.get_zone(zone_id)

    go_for_it = env.skip_confirmations or formatting.confirm(
        "Attempt to update DNS records for %s"
        % instance['fullyQualifiedDomainName'])

    if not go_for_it:
        raise exceptions.CLIAbort("Aborting DNS sync")

    both = False
    if not ptr and not a_record and not aaaa_record:
        both = True

    if both or a_record:
        sync_a_record()

    if both or ptr:
        sync_ptr_record()

    if aaaa_record:
        sync_aaaa_record()
476667
def get_domain_name(url):
    
    if not url.startswith("http"):
        url = "http://" + url
    if not is_valid_url(url):
        raise ValueError("Invalid URL '%s'" % url)
    parse = urlparse(url)
    return parse.netloc
107017
def _query_dns(self, host: str, family: int=socket.AF_INET) \
            -> dns.resolver.Answer:
        '''
        '''
        record_type = {socket.AF_INET: 'A', socket.AF_INET6: 'AAAA'}[family]

        event_loop = asyncio.get_event_loop()
        query = functools.partial(
            self._dns_resolver.query, host, record_type,
            source=self._bind_address)

        try:
            answer = yield from event_loop.run_in_executor(None, query)
        except (dns.resolver.NXDOMAIN, dns.resolver.NoAnswer) as error:
            # dnspython doesn't raise an instance with a message, so use the
            # class name instead.
            raise DNSNotFound(
                'DNS resolution failed: {error}'
                .format(error=wpull.util.get_exception_message(error))
            ) from error
        except dns.exception.DNSException as error:
            raise NetworkError(
                'DNS resolution error: {error}'
                .format(error=wpull.util.get_exception_message(error))
            ) from error
        else:
            return answer
1148342
def dnsdumpster(domain, output_dir):
    """"""
    response = requests.Session().get('https://dnsdumpster.com/').text
    csrf_token = re.search(
        r"name='csrfmiddlewaretoken' value='(.*?)'", response).group(1)

    cookies = {'csrftoken': csrf_token}
    headers = {'Referer': 'https://dnsdumpster.com/'}
    data = {'csrfmiddlewaretoken': csrf_token, 'targetip': domain}
    response = requests.Session().post(
        'https://dnsdumpster.com/', cookies=cookies, data=data, headers=headers)

    image = requests.get('https://dnsdumpster.com/static/map/%s.png' % domain)
    if image.status_code == 200:
        with open('%s/%s.png' % (output_dir, domain), 'wb') as f:
            f.write(image.content)
973810
public static dns_stats get(nitro_service service) throws Exception{
		dns_stats obj = new dns_stats();
		dns_stats[] response = (dns_stats[])obj.stat_resources(service);
		return response[0];
	}
435828
def query(qname, rdtype=dns.rdatatype.A, rdclass=dns.rdataclass.IN,
          tcp=False, source=None, raise_on_no_answer=True, resolver=None):
    """"""
    if resolver is None:
        resolver = get_default_resolver()
    return resolver.query(qname, rdtype, rdclass, tcp, source, raise_on_no_answer)
715569
def dns_get_conf(self, domainName, environment):
        
        response = self.client.service.dns_get_conf(domainName, environment)
        dns_config = CotendoDNS(response)
        return dns_config
1144356
def fetch_archive(savedir, url, fname, force=False):
    """"""
    dest = pjoin(savedir, fname)
    if os.path.exists(dest) and not force:
        info("already have %s" % fname)
        return dest
    info("fetching %s into %s" % (url, savedir))
    if not os.path.exists(savedir):
        os.makedirs(savedir)
    req = urlopen(url)
    with open(dest, 'wb') as f:
        f.write(req.read())
    return dest
1109115
def _convert_dns_answer(cls, answer: dns.resolver.Answer) \
            -> Iterable[AddressInfo]:
        ''''''
        assert answer.rdtype in (dns.rdatatype.A, dns.rdatatype.AAAA)

        if answer.rdtype == dns.rdatatype.A:
            family = socket.AF_INET
        else:
            family = socket.AF_INET6

        for record in answer:
            ip_address = record.to_text()

            if family == socket.AF_INET6:
                flow_info, control_id = cls._get_ipv6_info(ip_address)
            else:
                flow_info = control_id = None

            yield AddressInfo(ip_address, family, flow_info, control_id)
135774
def update_record(self, dns_type, name, content, **kwargs):
        
        record = self.get_record(dns_type, name)
        data = {
            'type': dns_type,
            'name': name,
            'content': content
        }
        if kwargs.get('ttl') and kwargs['ttl'] != 1:
            data['ttl'] = kwargs['ttl']
        if kwargs.get('proxied') is True:
            data['proxied'] = True
        else:
            data['proxied'] = False
        content = self.request(
            urllib.parse.urljoin(self.api_url, self.zone['id'] + '/dns_records/' + record['id']),
            'put',
            data=data
        )
        print('DNS record successfully updated')
        return content['result']