Prüfe DNS auf IPv6 AAAA Record (#124)

* Add check for IPv6 AAAA record

* Adapt rating/resolvable
This commit is contained in:
Marian Steinbach 2019-07-15 22:59:33 +02:00 committed by GitHub
parent 4401683133
commit 68f2288617
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 14 deletions

View File

@ -6,7 +6,7 @@ RUN echo "http://dl-4.alpinelinux.org/alpine/v3.8/main" >> /etc/apk/repositories
apk update && \
apk --no-cache add chromium chromium-chromedriver python3-dev build-base git py3-lxml libxml2 libxml2-dev libxslt libxslt-dev libffi-dev openssl-dev && \
pip3 install --upgrade pip && \
pip3 install selenium==3.8.0 GitPython PyYAML beautifulsoup4==4.6.0 html-similarity==0.3.2 httpretty==0.9.4 feedparser==5.2.1 pyopenssl==18.0.0 requests==2.18.4 responses==0.9.0 smmap2==2.0.3 urllib3==1.22 google-cloud-datastore==1.7.0 tenacity==5.0.2 && \
pip3 install dnspython==1.16.0 selenium==3.8.0 GitPython PyYAML beautifulsoup4==4.6.0 html-similarity==0.3.2 httpretty==0.9.4 feedparser==5.2.1 pyopenssl==18.0.0 requests==2.18.4 responses==0.9.0 smmap2==2.0.3 urllib3==1.22 google-cloud-datastore==1.7.0 tenacity==5.0.2 && \
apk del python3-dev build-base
ADD cli.py /

View File

@ -5,10 +5,11 @@ URLs which are not resolvable are removed from the config.
"""
import logging
from socket import gethostbyname_ex
from urllib.parse import urlparse
from urllib.parse import urlunparse
import dns.resolver
from checks.abstract_checker import AbstractChecker
@ -27,8 +28,8 @@ class Checker(AbstractChecker):
results[url] = self.resolve_hostname(parsed.hostname)
# remove URL if non-resolvable
if not results[url]['resolvable']:
# remove URL if IPv4 non-resolvable
if not results[url]['resolvable_ipv4']:
self.config.remove_url(url)
return results
@ -39,17 +40,29 @@ class Checker(AbstractChecker):
"""
result = {
'hostname': hostname,
'resolvable': False,
'resolvable_ipv4': False,
'resolvable_ipv6': False,
'aliases': [],
'ipv4_addresses': [],
'ipv6_addresses': [],
}
# IPv4
try:
hostname, aliases, ipv4_addresses = gethostbyname_ex(hostname)
result['resolvable'] = True
result['aliases'] = aliases
result['ipv4_addresses'] = ipv4_addresses
answers = dns.resolver.query(hostname, "A")
result['resolvable_ipv4'] = True
for rdata in answers:
result['ipv4_addresses'].append(rdata.address)
except Exception as e:
logging.debug("Hostname %s not resolvable. Exception: %r" % (hostname, e))
logging.debug("Hostname %s not resolvable via IPv4. Exception: %r" % (hostname, e))
# IPv6
try:
answers = dns.resolver.query(hostname, "AAAA")
result['resolvable_ipv6'] = True
for rdata in answers:
result['ipv6_addresses'].append(rdata.address)
except Exception as e:
logging.debug("Hostname %s not resolvable via IPv4. Exception: %r" % (hostname, e))
return result

View File

@ -1,4 +1,6 @@
import unittest
import logging
import sys
from pprint import pprint
from checks import dns_resolution
@ -6,7 +8,7 @@ from checks.config import Config
class TestDNSResolution(unittest.TestCase):
def test_google(self):
def runTest(self):
"""Resolves www.google.com"""
url = 'https://www.google.com/'
config = Config(urls=[url])
@ -15,9 +17,13 @@ class TestDNSResolution(unittest.TestCase):
self.assertIn(url, result)
self.assertEqual(result[url]['hostname'], 'www.google.com')
self.assertTrue(result[url], 'resolvable')
self.assertTrue(result[url], 'resolvable_ipv4')
self.assertTrue(result[url], 'resolvable_ipv6')
self.assertIsInstance(result[url]['ipv4_addresses'], list)
self.assertNotEqual(result[url]['ipv4_addresses'], [])
if __name__ == '__main__':
unittest.main()
logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)
unittest.TextTestRunner().run(TestDNSResolution())
#unittest.main()

View File

@ -20,7 +20,7 @@ class Rater(AbstractRater):
count = 0
for url in self.check_results['dns_resolution']:
if self.check_results['dns_resolution'][url]['resolvable']:
if self.check_results['dns_resolution'][url]['resolvable_ipv4']:
count += 1
if count > 0: