chg: [rbl] Added a timeout parameter to change the resolver timeout & lifetime if needed

pull/488/head
chrisr3d 2021-04-16 22:00:27 +02:00
parent 4a20045787
commit dbff9b3aa8
No known key found for this signature in database
GPG Key ID: 6BBED1B63A6D639F
1 changed files with 8 additions and 4 deletions

View File

@ -3,9 +3,6 @@ import sys
try: try:
import dns.resolver import dns.resolver
resolver = dns.resolver.Resolver()
resolver.timeout = 0.2
resolver.lifetime = 0.2
except ImportError: except ImportError:
print("dnspython3 is missing, use 'pip install dnspython3' to install it.") print("dnspython3 is missing, use 'pip install dnspython3' to install it.")
sys.exit(0) sys.exit(0)
@ -15,7 +12,7 @@ mispattributes = {'input': ['ip-src', 'ip-dst'], 'output': ['text']}
moduleinfo = {'version': '0.2', 'author': 'Christian Studer', moduleinfo = {'version': '0.2', 'author': 'Christian Studer',
'description': 'Check an IPv4 address against known RBLs.', 'description': 'Check an IPv4 address against known RBLs.',
'module-type': ['expansion', 'hover']} 'module-type': ['expansion', 'hover']}
moduleconfig = [] moduleconfig = ['timeout']
rbls = ( rbls = (
"spam.spamrats.com", "spam.spamrats.com",
@ -88,6 +85,13 @@ def handler(q=False):
else: else:
misperrors['error'] = "Unsupported attributes type" misperrors['error'] = "Unsupported attributes type"
return misperrors return misperrors
resolver = dns.resolver.Resolver()
try:
timeout = float(request['config']['timeout'])
except (KeyError, ValueError):
timeout = 0.4
resolver.timeout = timeout
resolver.lifetime = timeout
infos = {} infos = {}
ipRev = '.'.join(ip.split('.')[::-1]) ipRev = '.'.join(ip.split('.')[::-1])
for rbl in rbls: for rbl in rbls: