Advertisement
c0d3dsk1lls

Capture_Packets

Jun 27th, 2022
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.59 KB | None | 0 0
  1. from struct import pack
  2. import time
  3. class PCAPFile:
  4.     def __init__(self, filename):
  5.         self.fp = open(filename, 'wb')
  6.         header = pack('!IHHiIII', 0xa1b2c3d4, 2, 4, 0, 0, 65535, 0)
  7.         print(header)
  8.         self.fp.write(header)
  9.        
  10.     def write(self, data):
  11.         seconds, mseconds = (int(part) for part in str(time.time()).split('.'))
  12.         length = len(data)
  13.         message = pack('!IIII', seconds, mseconds, length, length)
  14.         self.fp.write(message)
  15.         self.fp.write(data)
  16.        
  17.     def close(self):
  18.         self.fp.close()
  19.            
  20.  
  21.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement