<commit_before># -*- coding: utf-8 -*-
'''
Reference:
https://stat.ripe.net/docs/data_api
https://github.com/RIPE-NCC/whois/wiki/WHOIS-REST-API-abuse-contact

TODO: Load RIPE networks prefixes into memory.
TODO: Compare each IP with networks prefixes loaded.
TODO: If ip matches, query RIPE
'''
from __future__ import unicode_literals
import sys

from intelmq.bots.experts.ripencc_abuse_contact import lib
from intelmq.lib.bot import Bot


class RIPENCCExpertBot(Bot):

    def init(self):
        self.query_db_asn = getattr(self.parameters, 'query_ripe_db_asn', True)
        self.query_db_ip = getattr(self.parameters, 'query_ripe_db_ip', True)
        self.query_stat_asn = getattr(self.parameters, 'query_ripe_stat', True)
        self.query_stat_ip = getattr(self.parameters, 'query_ripe_stat', True)

    def process(self):
        event = self.receive_message()

        if event is None:
            self.acknowledge_message()
            return

        for key in ['source.', 'destination.']:
            ip_key = key + "ip"
            abuse_key = key + "abuse_contact"
            asn_key = key + "asn"

            ip = event.get(ip_key, None)
            abuse = (event.get(abuse_key.split(',')) if abuse_key in event
                     else [])
            asn = event.get(asn_key, None)
            if self.query_db_asn and asn:
                abuse.extend(lib.query_asn(asn))
            if self.query_db_ip and ip:
                abuse.extend(lib.query_ripedb(ip))
            if self.query_stat_asn and asn:
                abuse.extend(lib.query_ripestat(asn))
            if self.query_stat_ip and ip:
                abuse.extend(lib.query_ripestat(ip))

            event.add(abuse_key, ','.join(set(abuse)), force=True)

        self.send_message(event)
        self.acknowledge_message()

if __name__ == "__main__":
    bot = RIPENCCExpertBot(sys.argv[1])
    bot.start()<commit_msg>This should fix an issue in intelmq/bots/experts/ripencc_abuse_contact/expert.py<commit_after># -*- coding: utf-8 -*-
'''
Reference:
https://stat.ripe.net/docs/data_api
https://github.com/RIPE-NCC/whois/wiki/WHOIS-REST-API-abuse-contact

TODO: Load RIPE networks prefixes into memory.
TODO: Compare each IP with networks prefixes loaded.
TODO: If ip matches, query RIPE
'''
from __future__ import unicode_literals
import sys

from intelmq.bots.experts.ripencc_abuse_contact import lib
from intelmq.lib.bot import Bot


class RIPENCCExpertBot(Bot):

    def init(self):
        self.query_db_asn = getattr(self.parameters, 'query_ripe_db_asn', True)
        self.query_db_ip = getattr(self.parameters, 'query_ripe_db_ip', True)
        self.query_stat_asn = getattr(self.parameters, 'query_ripe_stat', True)
        self.query_stat_ip = getattr(self.parameters, 'query_ripe_stat', True)

    def process(self):
        event = self.receive_message()

        if event is None:
            self.acknowledge_message()
            return

        for key in ['source.', 'destination.']:
            ip_key = key + "ip"
            abuse_key = key + "abuse_contact"
            asn_key = key + "asn"

            ip = event.get(ip_key, None)
            abuse = (event.get(abuse_key).split(',') if abuse_key in event
                     else [])
            asn = event.get(asn_key, None)
            if self.query_db_asn and asn:
                abuse.extend(lib.query_asn(asn))
            if self.query_db_ip and ip:
                abuse.extend(lib.query_ripedb(ip))
            if self.query_stat_asn and asn:
                abuse.extend(lib.query_ripestat(asn))
            if self.query_stat_ip and ip:
                abuse.extend(lib.query_ripestat(ip))

            event.add(abuse_key, ','.join(filter(None, set(abuse))), force=True)

        self.send_message(event)
        self.acknowledge_message()

if __name__ == "__main__":
    bot = RIPENCCExpertBot(sys.argv[1])
    bot.start()
{'fraction_non_alphanumeric': 0.11210647555669312, 'fraction_numerical': 0.0010238034297414896, 'mean_word_length': 2.4861730597680642, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6641920', 'n_tokens_mistral': 1339, 'n_tokens_neox': 1302, 'n_words': 264}