Use ipaddress everywhere.
@@ -19,7 +19,7 @@ def is_private(address):
Returns:
True or False
'''
- return ipaddress.ip_address(address).is_private
+ return address.is_private
def extract_macs(packet):
@@ -74,16 +74,16 @@ def get_indiv_source(sessions, address_type='MAC'):
# Compute the IP/MAC address pairs
if os.environ.get('POSEIDON_PUBLIC_SESSIONS'):
- pair_1 = source_address + '-' + source_mac
- pair_2 = destination_address + '-' + destination_mac
+ pair_1 = str(source_address) + '-' + source_mac
+ pair_2 = str(destination_address) + '-' + destination_mac
ip_mac_pairs[pair_1] += 1
ip_mac_pairs[pair_2] += 1
else:
# Only look at sessions with an internal IP address
# This shouldn't actually be necessary at this stage
if is_private(source_address) or is_private(destination_address):
- pair_1 = source_address + '-' + source_mac
- pair_2 = destination_address + '-' + destination_mac
+ pair_1 = str(source_address) + '-' + source_mac
+ pair_2 = str(destination_address) + '-' + destination_mac
if is_private(source_address):
ip_mac_pairs[pair_1] += 1
if is_private(destination_address):
@@ -130,7 +130,7 @@ def get_source(sessions, address_type='MAC'):
if address_type == 'MAC':
capture_source = '00:00:00:00:00:00'
else:
- capture_source = '0.0.0.0'
+ capture_source = ipaddress.ip_address('0.0.0.0')
for session_dict in sessions:
# Get the ip mac address pairs for each session dict
@@ -149,7 +149,7 @@ def get_source(sessions, address_type='MAC'):
if address_type == 'MAC':
capture_source = sorted_sources[0].split('-')[1]
else:
- capture_source = sorted_sources[0].split('-')[0]
+ capture_source = ipaddress.ip_address(sorted_sources[0].split('-')[0])
else:
if address_type == 'MAC':
@@ -400,7 +400,7 @@ def get_ip_port(socket_str):
address, port
"""
splitter_index = socket_str.rindex(':')
- address = socket_str[0:splitter_index]
+ address = ipaddress.ip_address(socket_str[0:splitter_index])
port = socket_str[splitter_index + 1:]
return address, port
