dshield_to_tracing.py 740 B

123456789101112131415161718192021222324252627282930313233
  1. import sys
  2. import csv
  3. import random
  4. import re
  5. from collections import defaultdict
  6. if len(sys.argv) < 2:
  7. print("usage: python %s dshield_stats.csv outfile.csv" % sys.argv[0])
  8. sys.exit(1)
  9. csv_filename_in = sys.argv[1]
  10. csv_fd_in = open(csv_filename_in, newline='')
  11. csv_reader = csv.reader(csv_fd_in, delimiter=' ')
  12. csv_filename_out = sys.argv[2]
  13. csv_fd_out = open(csv_filename_out, "w")
  14. print("converting DShield data from %s to %s" % (csv_filename_in, csv_filename_out))
  15. cnt = 0
  16. for val in csv_reader:
  17. if len(val) < 9:
  18. continue
  19. if cnt % 1000000 == 0:
  20. print("got %d so far" % cnt)
  21. cnt += 1
  22. csv_fd_out.write("%s\t%s\t%s\t%s\t%s\t%s\n" %
  23. (val[3], val[4], val[5], val[6], val[7], val[8]))
  24. csv_fd_in.close()
  25. csv_fd_out.close()