Skip to content

Commit

Permalink
Ported the code to python 3.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahmed Lotfy authored and wisepythagoras committed Jan 21, 2021
1 parent abf3030 commit 56d5fd0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
3 changes: 1 addition & 2 deletions gather_and_train.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import sys
import json
import utils
from sklearn.externals import joblib


# Read the configuration and start training.
Expand Down Expand Up @@ -65,7 +64,7 @@

i += 1

print " {} pcap files".format(i)
print(f" {i} pcap files")

# Increment the label
current_label += 1
Expand Down
10 changes: 5 additions & 5 deletions predict.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
sys.exit(1)

elif os.path.exists('config.json') == False:
print "No configuration found"
print("No configuration found")
sys.exit(1)

elif os.path.exists('./classifier-nb.dmp') == False:
print "No classifier dump found; train first"
print("No classifier dump found; train first")
sys.exit(1)

elif os.path.exists(sys.argv[1]) == False:
print "The input file was not found"
print("The input file was not found")
sys.exit(1)

# Read the configuration and start training.
Expand Down Expand Up @@ -57,7 +57,7 @@
# Run the prediction.
prediction = classifier.predict([stream])

print classifier.predict_proba([stream])
print(classifier.predict_proba([stream]))

# Print the results.
print("[{}] Prediction: {}".format(prediction[0], base_labels[prediction[0] - 1]))
print(f"[{prediction[0]}] Prediction: {base_labels[prediction[0] - 1]}")
7 changes: 5 additions & 2 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,11 @@ def read_pcap_file(file):
ratio = float(incoming_packets) / (outgoing_packets if outgoing_packets != 0 else 1)

# Print some details.
print "OUT: {}, IN: {}, TOTAL: {}, SIZE: {}, RATIO: {}".format(\
outgoing_packets, incoming_packets, total_number_of_packets, incoming_size, ratio)
print(f'OUT: {outgoing_packets},' +
f'IN: {incoming_packets},' +
f'TOTAL: {total_number_of_packets},' +
f'SIZE: {incoming_size},' +
f'RATIO: {ratio}')

# Reverse the array to append the other information.
sizes.reverse()
Expand Down

0 comments on commit 56d5fd0

Please sign in to comment.