Guest User

Untitled

a guest
Jan 24th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. require 'rubygems'
  2. require 'json'
  3. require 'socket'
  4. require 'time'
  5.  
  6. def make_clean(str)
  7. str.force_encoding("ASCII-8BIT") if str.respond_to? :force_encoding
  8. regex = Regexp.new('[\x00-\x1f\x7f-\xff]', nil, 'n')
  9. str.to_s.gsub(regex,'.')
  10. end
  11.  
  12. s = TCPSocket.open('localhost',9999)
  13. f = File.open('out')
  14.  
  15. c = 4
  16.  
  17. f.each_line { |x|
  18. c += 1
  19. y = x.split(/,/)
  20.  
  21. srcdata = y[14].split("=",2)
  22. dstdata = y[15].split("=",2)
  23.  
  24. sd = srcdata.count > 1 ? srcdata[0] + '="' + make_clean(srcdata[1].unpack('m')[0]) + '"' : ''
  25. dd = dstdata.count > 1 ? dstdata[0] + '="' + make_clean(dstdata[1].unpack('m')[0]) + '"' : ''
  26.  
  27. jobj = {
  28. :StartTime => y[0],
  29. :Proto => y[1],
  30. :SrcMac => y[2],
  31. :DstMac => y[3],
  32. :SrcAddr => y[4],
  33. :Sport => y[5],
  34. :Dir => y[6],
  35. :DstAddr => y[7],
  36. :Dport => y[8],
  37. :SrcPkts => y[9],
  38. :DstPkts => y[10],
  39. :SrcBytes => y[11],
  40. :DstBytes => y[12],
  41. :State => y[13],
  42. :srcUdata => sd,
  43. :dstUdata => dd
  44. }
  45.  
  46. s.write(jobj.to_json)
  47.  
  48. puts Time.now.to_s + ": currently at #{c} - #{y[0]}" if (c % 100000) == 0
  49. }
  50.  
  51. s.close
Add Comment
Please, Sign In to add comment