fix: [IPAddress] catch empty config error

This commit is contained in:
Terrtia 2020-02-03 15:29:37 +01:00
parent 4d8db3fcc4
commit 8770bf05d7
No known key found for this signature in database
GPG key ID: 1E1B1F50D84613D0

View file

@ -6,7 +6,7 @@ The IP Module
This module is consuming the global channel. This module is consuming the global channel.
It first performs a regex to find IP addresses and then matches those IPs to It first performs a regex to find IP addresses and then matches those IPs to
some configured ip ranges. some configured ip ranges.
The list of IP ranges are expected to be in CIDR format (e.g. 192.168.0.0/16) The list of IP ranges are expected to be in CIDR format (e.g. 192.168.0.0/16)
@ -16,6 +16,7 @@ and should be defined in the config.cfg file, under the [IP] section
import time import time
import re import re
import sys
from pubsublogger import publisher from pubsublogger import publisher
from packages import Paste from packages import Paste
from Helper import Process from Helper import Process
@ -60,8 +61,12 @@ if __name__ == '__main__':
p = Process(config_section) p = Process(config_section)
ip_networks = [] ip_networks = []
for network in p.config.get("IP", "networks").split(","): try:
ip_networks.append(IPv4Network(network)) for network in p.config.get("IP", "networks").split(","):
ip_networks.append(IPv4Network(network))
except:
print('Please provide a list of valid IP addresses')
sys.exit(0)
# Sent to the logging a description of the module # Sent to the logging a description of the module
@ -78,4 +83,3 @@ if __name__ == '__main__':
# Do something with the message from the queue # Do something with the message from the queue
search_ip(message) search_ip(message)