mirror of
https://github.com/netzbegruenung/green-spider.git
synced 2024-05-01 08:34:51 +02:00
Prüfe DNS auf IPv6 AAAA Record (#124)
* Add check for IPv6 AAAA record * Adapt rating/resolvable
This commit is contained in:
parent
4401683133
commit
68f2288617
|
@ -6,7 +6,7 @@ RUN echo "http://dl-4.alpinelinux.org/alpine/v3.8/main" >> /etc/apk/repositories
|
||||||
apk update && \
|
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 && \
|
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 --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
|
apk del python3-dev build-base
|
||||||
|
|
||||||
ADD cli.py /
|
ADD cli.py /
|
||||||
|
|
|
@ -5,10 +5,11 @@ URLs which are not resolvable are removed from the config.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
from socket import gethostbyname_ex
|
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
from urllib.parse import urlunparse
|
from urllib.parse import urlunparse
|
||||||
|
|
||||||
|
import dns.resolver
|
||||||
|
|
||||||
from checks.abstract_checker import AbstractChecker
|
from checks.abstract_checker import AbstractChecker
|
||||||
|
|
||||||
|
|
||||||
|
@ -27,8 +28,8 @@ class Checker(AbstractChecker):
|
||||||
|
|
||||||
results[url] = self.resolve_hostname(parsed.hostname)
|
results[url] = self.resolve_hostname(parsed.hostname)
|
||||||
|
|
||||||
# remove URL if non-resolvable
|
# remove URL if IPv4 non-resolvable
|
||||||
if not results[url]['resolvable']:
|
if not results[url]['resolvable_ipv4']:
|
||||||
self.config.remove_url(url)
|
self.config.remove_url(url)
|
||||||
|
|
||||||
return results
|
return results
|
||||||
|
@ -39,17 +40,29 @@ class Checker(AbstractChecker):
|
||||||
"""
|
"""
|
||||||
result = {
|
result = {
|
||||||
'hostname': hostname,
|
'hostname': hostname,
|
||||||
'resolvable': False,
|
'resolvable_ipv4': False,
|
||||||
|
'resolvable_ipv6': False,
|
||||||
'aliases': [],
|
'aliases': [],
|
||||||
'ipv4_addresses': [],
|
'ipv4_addresses': [],
|
||||||
|
'ipv6_addresses': [],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# IPv4
|
||||||
try:
|
try:
|
||||||
hostname, aliases, ipv4_addresses = gethostbyname_ex(hostname)
|
answers = dns.resolver.query(hostname, "A")
|
||||||
result['resolvable'] = True
|
result['resolvable_ipv4'] = True
|
||||||
result['aliases'] = aliases
|
for rdata in answers:
|
||||||
result['ipv4_addresses'] = ipv4_addresses
|
result['ipv4_addresses'].append(rdata.address)
|
||||||
except Exception as e:
|
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
|
return result
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
import unittest
|
import unittest
|
||||||
|
import logging
|
||||||
|
import sys
|
||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
|
|
||||||
from checks import dns_resolution
|
from checks import dns_resolution
|
||||||
|
@ -6,7 +8,7 @@ from checks.config import Config
|
||||||
|
|
||||||
class TestDNSResolution(unittest.TestCase):
|
class TestDNSResolution(unittest.TestCase):
|
||||||
|
|
||||||
def test_google(self):
|
def runTest(self):
|
||||||
"""Resolves www.google.com"""
|
"""Resolves www.google.com"""
|
||||||
url = 'https://www.google.com/'
|
url = 'https://www.google.com/'
|
||||||
config = Config(urls=[url])
|
config = Config(urls=[url])
|
||||||
|
@ -15,9 +17,13 @@ class TestDNSResolution(unittest.TestCase):
|
||||||
|
|
||||||
self.assertIn(url, result)
|
self.assertIn(url, result)
|
||||||
self.assertEqual(result[url]['hostname'], 'www.google.com')
|
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.assertIsInstance(result[url]['ipv4_addresses'], list)
|
||||||
self.assertNotEqual(result[url]['ipv4_addresses'], [])
|
self.assertNotEqual(result[url]['ipv4_addresses'], [])
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)
|
||||||
|
unittest.TextTestRunner().run(TestDNSResolution())
|
||||||
|
|
||||||
|
#unittest.main()
|
||||||
|
|
|
@ -20,7 +20,7 @@ class Rater(AbstractRater):
|
||||||
|
|
||||||
count = 0
|
count = 0
|
||||||
for url in self.check_results['dns_resolution']:
|
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
|
count += 1
|
||||||
|
|
||||||
if count > 0:
|
if count > 0:
|
||||||
|
|
Loading…
Reference in a new issue