Skip to content

Commit

Permalink
change saved ip
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastienBtr committed Nov 28, 2019
1 parent 0dc8c97 commit 11c511d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
26 changes: 16 additions & 10 deletions analyse_packets.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,13 @@ def analyse_packets(pkt):
# If we already have the stream in the dict or not
if (streamIndex not in packet_dict):
# Get the remote ip of the stream
ipClient = pkt.ipv6.src if 'IPV6' in pkt else pkt.ip.src
ipServer = pkt.ipv6.dst if 'IPV6' in pkt else pkt.ip.dst
save_new_stream(streamIndex, timestamp, ipClient, ipServer, pkt, protocol)
ip = ''
if ('IPV6' in pkt):
ip = pkt.ipv6.src if pkt.ipv6.src != LOCAL_IP else pkt.ipv6.dst
else:
ip = pkt.ip.src if pkt.ip.src != LOCAL_IP else pkt.ip.dst

save_new_stream(streamIndex, timestamp, ip, pkt, protocol)
else:
last_time = packet_dict[streamIndex]['endTime']
# We don't use pkt[protocol].time_delta because it is not available in UDP
Expand Down Expand Up @@ -60,16 +64,13 @@ def get_packet_size(pkt):


# Save a new stream and its first packet in the dict
def save_new_stream(stream_id, timestamp, ipClient, ipServer, pkt, protocol):
domainSrc = reverse_dns(ipClient)
domainDst = reverse_dns(ipServer)
def save_new_stream(stream_id, timestamp, ip, pkt, protocol):
domain = reverse_dns(ip)
packet_dict[stream_id] = {
'sumDelta': 0,
'averageDelta': 0,
'ipClient': ipClient,
'ipServer': ipServer,
'domainSrc': domainSrc,
'domainDst': domainDst,
'ip': ip,
'domain': domain,
'numberOfPackets': 1,
'totalMbSize': get_packet_size(pkt),
'startTime': timestamp,
Expand Down Expand Up @@ -97,6 +98,11 @@ def reverse_dns(ip):
except:
return ""

# Check if we have the necessaries environment variables
environment.check_analyse_env()

# env var
LOCAL_IP = os.getenv('LOCAL_IP')

# Arguments available
parser = argparse.ArgumentParser()
Expand Down
2 changes: 1 addition & 1 deletion csv_saver.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import csv
import os

csv_columns = ['ipClient', 'ipServer', 'domainSrc', 'domainDst',
csv_columns = ['ip', 'domain',
'numberOfPackets', 'totalMbSize', 'startTime', 'endTime', 'protocol']

# Insert a row in the results csv file
Expand Down
6 changes: 6 additions & 0 deletions environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
from dotenv import load_dotenv
load_dotenv()

def check_analyse_env():
if ((os.getenv('LOCAL_IP') is None or os.getenv('LOCAL_IP') == "")
and (os.getenv('LOCAL_IPV6') is None or os.getenv('LOCAL_IPV6') == "")):
raise Exception(
'\n\nPlease complete the following environment variables in the .env file:\nLOCAL_IP\n')

# Check if we have all the environment variables for the sniffer
def check_sniffer_env():
if (((os.getenv('LISTENED_IP') is None or os.getenv('LISTENED_IP') == "")
Expand Down

0 comments on commit 11c511d

Please sign in to comment.