Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specify nameservers directly #18

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added
- nameserver specification support for DNSBLIpChecker


## [1.1.0] - 2020-09-27
### Added
- ipv6 support for DNSBLIpChecker
Expand Down
6 changes: 4 additions & 2 deletions pydnsbl/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,13 @@ class BaseDNSBLChecker(abc.ABC):
* providers(list) - list of providers (Provider instance or str)
* timeout(int) - timeout of dns requests will be passed to resolver
* tries(int) - retry times
* ns(list) - nameservers to use for lookup
"""

def __init__(self, providers=BASE_PROVIDERS, timeout=5,
tries=2, concurrency=200, loop=None):
tries=2, concurrency=200, loop=None, ns=None):
self.providers = []
self.ns = ns
for provider in providers:
if not isinstance(provider, Provider):
raise ValueError('providers should contain only Provider instances')
Expand All @@ -101,7 +103,7 @@ def __init__(self, providers=BASE_PROVIDERS, timeout=5,
asyncio.set_event_loop(self._loop)
else:
self._loop = loop
self._resolver = aiodns.DNSResolver(timeout=timeout, tries=tries, loop=self._loop)
self._resolver = aiodns.DNSResolver(timeout=timeout, tries=tries, loop=self._loop, nameservers=ns)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine, but there is questions on the other part of this PR

self._semaphore = asyncio.Semaphore(concurrency)


Expand Down
24 changes: 19 additions & 5 deletions pydnsbl/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
Place to define providers.
Most part of _BASE_PROVIDERS was taken from https://github.com/vincecarney/dnsbl
"""
import os

### DNSBL CATEGORIES ###
# providers answers could be interpreted in one of the following categories
DNSBL_CATEGORY_UNKNOWN = 'unknown'
Expand All @@ -12,11 +14,17 @@
DNSBL_CATEGORY_CNC = 'cnc'
DNSBL_CATEGORY_ABUSED = 'abused'
DNSBL_CATEGORY_LEGIT = 'legit'
DNSBL_CATEGORY_DYNAMIC = 'dynamic'

class Provider(object):

def __init__(self, host):
def __init__(self, host, ns=None):
"""
host: the hostname of provider
ns: the nameserver IP to use for direct lookup
"""
self.host = host
self.ns = ns
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As i understand there is no effect of specifying ns for Provider in the scope of this PR?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this was used in other code not included.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still cant figure out how ns affects resolver


def process_response(self, response):
"""
Expand Down Expand Up @@ -57,6 +65,8 @@ def process_response(self, response):
categories.add(DNSBL_CATEGORY_SPAM)
elif result.host in ['127.0.0.4', '127.0.0.5', '127.0.0.6', '127.0.0.7']:
categories.add(DNSBL_CATEGORY_EXPLOITS)
elif result.host in ['127.0.0.10', '127.0.0.11']:
categories.add(DNSBL_CATEGORY_DYNAMIC)
else:
categories.add(DNSBL_CATEGORY_UNKNOWN)
return categories
Expand Down Expand Up @@ -138,8 +148,8 @@ class DblSpamhaus(Provider):
'127.0.1.106': {DNSBL_CATEGORY_ABUSED, DNSBL_CATEGORY_LEGIT, DNSBL_CATEGORY_CNC}
}

def __init__(self, host='dbl.spamhaus.org'):
Provider.__init__(self, host=host)
def __init__(self, host='dbl.spamhaus.org', ns=None):
Provider.__init__(self, host=host, ns=ns)

def process_response(self, response):
categories = set()
Expand All @@ -156,5 +166,9 @@ def process_response(self, response):
'rhsbl.sorbs.net '
]

BASE_PROVIDERS = [Provider(host) for host in _BASE_PROVIDERS] + [ZenSpamhaus()]
BASE_DOMAIN_PROVIDERS = [Provider(host) for host in _DOMAIN_PROVIDERS] + [DblSpamhaus()]
BASE_PROVIDERS = [Provider(host) for host in _BASE_PROVIDERS]
BASE_DOMAIN_PROVIDERS = [Provider(host) for host in _DOMAIN_PROVIDERS]

if os.getenv('USE_SPAMHAUS', 'false') == 'true':
BASE_PROVIDERS.append(ZenSpamhaus())
BASE_DOMAIN_PROVIDERS.append(DblSpamhaus())
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def get_long_description():

setup(
name='pydnsbl',
version='1.1.2',
version='1.1.5',
description='Async dnsbl lists checker based on asyncio/aiodns.',
long_description=get_long_description(),
long_description_content_type='text/markdown',
Expand Down