03.09.2013 Views

Implementation of data collection tools using NetFlow for statistical ...

Implementation of data collection tools using NetFlow for statistical ...

Implementation of data collection tools using NetFlow for statistical ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

8 Appendix<br />

# Remove the first line from the lists, as these contain the<br />

# actual name <strong>of</strong> the fields such as PROTO, BYTE and PACKETS<br />

# instead <strong>of</strong> the values itself. MySQL doesn't like doing<br />

# numerical calculations on fields containing text, <strong>for</strong> instance.<br />

v4_out.pop(0)<br />

v4_in.pop(0)<br />

v4_attack.pop(0)<br />

# Emptying the <strong>data</strong>base be<strong>for</strong>e new values are inserted.<br />

cursor.execute("TRUNCATE TABLE AS_in_v4")<br />

cursor.execute("TRUNCATE TABLE AS_out_v4")<br />

cursor.execute("TRUNCATE TABLE AS_attack_v4")<br />

# Looping through each list and inserting the values<br />

# into MySQL.<br />

# Traffic going OUT from I2B<br />

<strong>for</strong> kolumn in v4_out:<br />

cursor.execute("""INSERT INTO AS_out_v4 (DST_AS, packets,<br />

bytes) VALUES (%s, %s, %s)""", (kolumn[9], kolumn[30],<br />

kolumn[32]))<br />

# Note:<br />

# kolumn 9, 30 and 32 are the delimited fields which<br />

# contain the <strong>data</strong> we want to save. In this case, the<br />

# destination AS, the number <strong>of</strong> packets and bytes sent.<br />

# Traffic going IN to I2B<br />

<strong>for</strong> kolumn in v4_in:<br />

cursor.execute("INSERT INTO AS_in_v4 (SRC_AS, packets, bytes)<br />

VALUES (%s, %s, %s)", (kolumn[8], kolumn[30], kolumn[32]))<br />

# Note:<br />

# kolumn 8, 30 and 32 are the delimited fields which<br />

# contain the <strong>data</strong> we want to save. In this case, the<br />

# source AS, the number <strong>of</strong> packets and bytes received.<br />

# Attacking AS<br />

<strong>for</strong> kolumn in v4_attack:<br />

cursor.execute("INSERT INTO AS_attack_v4 (DST_AS, SRC_IP,<br />

DST_IP, DST_PORT, proto, packets, bytes) VALUES (%s, %s, %s, %s,<br />

%s, %s, %s)", (kolumn[9], kolumn[21], kolumn[22], kolumn[26],<br />

kolumn[28], kolumn[30], kolumn[32]))<br />

# Note:<br />

# kolumn 9, 21, 22, 26, 28, 30 and 32 are the delimited fields<br />

57

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!