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