Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_extract_macs():
source, dest = extract_macs('123456789ABCDEF123456780')
assert dest == '12:34:56:78:9a:bc'
assert source == 'de:f1:23:45:67:80'
source, dest = extract_macs('020406080A0C0E0103050700')
assert dest == '02:04:06:08:0a:0c'
assert source == '0e:01:03:05:07:00'
def test_extract_macs():
source, dest = extract_macs('123456789ABCDEF123456780')
assert dest == '12:34:56:78:9a:bc'
assert source == 'de:f1:23:45:67:80'
source, dest = extract_macs('020406080A0C0E0103050700')
assert dest == '02:04:06:08:0a:0c'
assert source == '0e:01:03:05:07:00'
num_sessions_rec = 0
num_external_rec = 0
num_tcp_sess_rec = 0
num_udp_sess_rec = 0
num_icmp_sess_rec = 0
# Iterate over all sessions and aggregate the info
other_ips = defaultdict(int)
for key, session in session_dict.items():
address_1, port_1 = get_ip_port(key[0])
address_2, port_2 = get_ip_port(key[1])
# Get the first packet and grab the macs from it
first_packet = session[0][1]
source_mac, destination_mac = extract_macs(first_packet)
# If the source is the cpature source
if (source_mac == capture_source
or address_1 == capture_source):
if is_private(address_2):
other_ips[address_2] += 1
num_sessions_init += 1
num_external_init += is_external(address_1, address_2)
num_tcp_sess_init += is_protocol(session, '06')
num_udp_sess_init += is_protocol(session, '11')
num_icmp_sess_init += is_protocol(session, '01')
if int(port_1) < max_port:
num_sport_init[int(port_1)] += 1