Tuesday, May 5, 2009

Issues with PCS

Not sure why the below code doesn't print out the same values three times...

import pcs
from pcs.packets.ethernet import *
from pcs.packets.ipv4 import *
from pcs.packets.tcp import *

def main():
from optparse import OptionParser

parser = OptionParser()
parser.add_option("-i", "--interface",
dest="interface", default=None,
help="Which interface to use for testing.")
(options, args) = parser.parse_args()
sniffer = pcs.PcapConnector(options.interface)

while 1:
rawPacket = sniffer.read()
etherPacket = ethernet(rawPacket)

if type(etherPacket.data) == ipv4:
ipv4Packet = ipv4(etherPacket.data.getbytes())

if type(ipv4Packet.data) == tcp:
tcpPacket = tcp(ipv4Packet.data.getbytes())

print etherPacket.data.data
print ipv4Packet.data
print tcpPacket
print '-------------------------------------'

No comments:

Post a Comment