def open(self, filename, literal=False): if not literal: parts = filename.split(':::') fn = parts[0] fd = open(fn, "rb") pc = pcap.open(fd) if len(parts) > 1: pos = int(parts[1]) fd.seek(pos) self._read(pc, fn, fd) else: fd = open(filename, "rb") pc = pcap.open(fd) self._read(pc, filename, fd)
def main(args): p = pcap.open(args.input) for i in p: e = ethernet(raw=i[1]) import pdb pdb.set_trace() print e
#!/usr/bin/env python #needs http://dirtbags.net/py-pcap/py-pcap-1.0.tar.gz to run import pcap import sys import struct import hashlib pcapFile = pcap.open(sys.argv[1]) i = 1 #maps packet data to a frame number icmpMeta = {} #maps a req frame number to its res reqToRes = {} #used to hold the checksum of payload so that the req id can be stored #thus allowing the res logic to get back to it. pairHolder = {} #loop assumes that res always after req for obj in pcapFile: isReq = True payload = obj[1] if payload[34] != '\x08': ext = 'res' isReq = False else: ext = 'req' data = payload[42:] #file('/tmp/icmp/' + str(i)+'.'+ext, 'w').write(data) checksum = "%02x%02x" % (ord(payload[36]), ord(payload[37])) revsum = '' revsum = checksum[::-1]
#! /usr/bin/env python import pcap import sys for fn in sys.argv[1:]: p = pcap.open(file(fn)) o = pcap.open(file(fn + '.new', 'w')) print "===================", fn print " Version ", p.version print " thiszone", p.thiszone print " sigfigs ", p.sigfigs print " snaplen ", p.snaplen print " linktype", p.linktype for pkt in p: print pkt o.write(pkt)
def main(opts, args): global surfaces global screen infile = args[1] pkts = opts.count screeninfo = pygame.display.Info() screenh = screeninfo.current_h screenw = screeninfo.current_w packets = pcap.open(file(infile)) sensed = 0 surfaces = {'left':View(hand='left'), 'right':View(), 'down':DownView()} inview = 'right' for _, pktdata in packets: pkts -= 1 # Skip the ip header _ = pktdata[:42] pktdata = pktdata[42:] dataheader = pktdata[:21] pktdata = pktdata[21:] #print dump2(dataheader) if not dataheader: continue if dataheader[0] == struct.pack('B', 0x21) : sensor = None if dataheader[1] == struct.pack('B', 0x02): sensor = 'down' sensed += 1 elif dataheader[1] == struct.pack('B', 0x03): sensor = 'left' sensed += 1 elif dataheader[1] == struct.pack('B', 0x04): sensor = 'right' sensed += 1 data = pktdata[4:] if sensor: surfaces[sensor].new_line(data) else: print dump2(pktdata) continue else: continue if sensed > 2: sensed = 0 if inview != 'all': surfaces[inview].draw() screen.blit(surfaces[inview].surface, (0, 0)) else: offset = 0 for view in ['left', 'right', 'down']: surfaces[view].draw() screen.blit(surfaces[view].surface, (offset, 0)) offset += screenw/3 clock.tick() pygame.display.update() for event in pygame.event.get(): setviewall = False setviewone = False if event.type == pygame.QUIT: return elif event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: return elif event.key == pygame.K_LEFT: if inview == 'all': setviewone = True inview = 'left' elif event.key == pygame.K_RIGHT: if inview == 'all': setviewone = True inview = 'right' elif event.key == pygame.K_DOWN: if inview == 'all': setviewone = True inview = 'down' elif event.key == pygame.K_UP: setviewall = True if inview != 'all': inview = 'all' elif event.type == pygame.VIDEORESIZE: print "RESIZE" screenw, screenh = event.dict['size'] screen = pygame.display.set_mode((screenw, screenh), pygame.RESIZABLE) if inview == 'all': setviewall = True else: setviewone = True print screeninfo.current_w, screeninfo.current_h if setviewall: for view in ['left','right']: surfaces[view].resize(screenw/3, screenh) surfaces['down'].resize(screenw/3, screenh) if setviewone: for view in ['left', 'right', 'down']: surfaces[view].resize(screenw, screenh) if pkts == 0: return
#!/usr/bin/env python # Installed from: http://dirtbags.net/py-pcap.html import pcap import argparse import sys import os sys.path.append(os.path.join(os.path.dirname(__file__), "..", "pox")) from pox.lib.packet.ethernet import * parser = argparse.ArgumentParser() parser.add_argument('-i', '--input') parser.add_argument('-o', '--output', default="pcap.trace") args = parser.parse_args() p = pcap.open(args.input) for i in p: e = ethernet(raw=i[1]) import pdb; pdb.set_trace() print e