Esempio n. 1
0
 def testPySharkBadFieldNames1(self):
     """This should fail because the second argument is not a list"""
     try:
         pkts = pyshark.iter(self.filename, 3, '')
         self.fail("Bad Field Names did not raise TypeError")
     except TypeError:
         pass
Esempio n. 2
0
 def testPySharkBadDisplayFilter(self):
     try:
         pkts = pyshark.iter(self.filename, ['frame.number', 'eth.type'],
                             55)
         self.fail("Bad Display Filter did not raise TypeError")
     except TypeError:
         pass
Esempio n. 3
0
 def testPySharkBadFilename2(self):
     """This should fail because the filename is None"""
     try:
         pkts = pyshark.iter(None, ['frame.number', 'eth.type'], '')
         self.fail("Bad Filename did not raise TypeError")
     except TypeError:
         pass
Esempio n. 4
0
 def testPySharkIteratorWildcard1(self):
     pkts = pyshark.iter(self.filename,
                         ['*'],
                         '')
     count = 0
     num_keys = len(pkts.next().keys())
     self.failUnless(num_keys == 55)
Esempio n. 5
0
 def testPySharkBadFilename1(self):
     """This should fail because the first argument is a number"""
     try:
         pkts = pyshark.iter(34, ['frame.number', 'eth.type'], '')
         self.fail("Bad Filename did not raise TypeError")
     except TypeError:
         pass
Esempio n. 6
0
 def testPySharkFilenameDoesntExist3(self):
     """This should fail because the filename is an empty string"""
     try:
         pkts = pyshark.iter("", ['frame.number', 'eth.type'], '')
         self.fail("Bad Filename did not raise PySharkError")
     except PySharkError:
         pass
Esempio n. 7
0
    def testAselTrueFieldsFalse(self):
        """allowSingleElementLists(True) and showEmptyFields(False)"""
        pkts = pyshark.iter(self.filename,
                            ['tcp.dstport', 'frame.number', 'arp.hw.type', 'udp.srcport', 'tcp.srcport'],
                            '')

        pkts.allowSingleElementLists(True)
        pkts.showEmptyFields(False)

        pktlistref = [
            {'frame.number': [1], 'udp.srcport': [60000]},
            {'frame.number': [2], 'udp.srcport': [60000]},
            {'frame.number': [3], 'arp.hw.type': [1]},
            {'frame.number': [4], 'arp.hw.type': [1]},
            {'frame.number': [5], 'arp.hw.type': [1]},
            {'frame.number': [6], 'udp.srcport': [60000]}]
        
        pktlist = []

        for i in range(1, 7):
            pkt = pkts.next()
            pktlist.append(pkt)

        #print pktlist
        self.failUnless(pktlist == pktlistref)
Esempio n. 8
0
 def testPySharkIteratorWildcard3(self):
     pkts = pyshark.iter(self.filename,
                         ['ip.*', 'eth.type'],
                         '')
     count = 0
     num_keys = len(pkts.next().keys())
     self.failUnless(num_keys == 25)
Esempio n. 9
0
    def testAselFalseFieldsFalse(self):
        """allowSingleElementLists(False) and showEmptyFields(False)"""
        pkts = pyshark.iter(self.filename,
                            ['tcp.dstport', 'frame.number', 'arp.hw.type', 'udp.srcport', 'tcp.srcport'],
                            '')

        pkts.allowSingleElementLists(False)
        pkts.showEmptyFields(False)

        pktlistref = [
            {'frame.number': 1, 'udp.srcport': 60000},
            {'frame.number': 2, 'udp.srcport': 60000},
            {'frame.number': 3, 'arp.hw.type': 1},
            {'frame.number': 4, 'arp.hw.type': 1},
            {'frame.number': 5, 'arp.hw.type': 1},
            {'frame.number': 6, 'udp.srcport': 60000}
            ]
                
        pktlist = []
        # We only need to look at the first 6 packets for this test
        for i in range(1, 7):
            pkt = pkts.next()
            pktlist.append(pkt)

        self.failUnless(pktlist == pktlistref)
Esempio n. 10
0
 def testPySharkDisplayFilter(self):
     """There are 74 UDP packets in the capture"""
     pkts = pyshark.iter(self.filename, ['frame.number', 'eth.type'], 'udp')
     count = 0
     for pkt in pkts:
         count += 1
     self.failUnless(count == 74)
Esempio n. 11
0
    def testWildcardAselFalseFieldsFalse(self):
        """Wildcard version of allowSingleElementLists(False) and showEmptyFields(False)"""
        pkts = pyshark.iter(self.filename,
                            ['tcp.dstport', 'udp.*', 'arp.hw.type', 'udp.srcport', 'tcp.srcport'],
                            '')

        pkts.allowSingleElementLists(False)
        pkts.showEmptyFields(False)

        pktlistref = [
            {'udp.checksum_coverage': 9, 'udp.length': 9, 'udp.checksum_bad': False,
             'udp.checksum': 5072, 'udp.dstport': 60000, 'udp.srcport': 60000,
             'udp.port': [60000, 60000], 'udp.checksum_good': True},
            {'udp.checksum_coverage': 9, 'udp.length': 9, 'udp.checksum_bad': False,
             'udp.checksum': 5077, 'udp.dstport': 60000, 'udp.srcport': 60000,
             'udp.port': [60000, 60000], 'udp.checksum_good': True},
            {'arp.hw.type': 1},
            {'arp.hw.type': 1},
            {'arp.hw.type': 1},
            {'udp.checksum_coverage': 9, 'udp.length': 9, 'udp.checksum_bad': False,
             'udp.checksum': 5086, 'udp.dstport': 60000, 'udp.srcport': 60000,
             'udp.port': [60000, 60000], 'udp.checksum_good': True}
            ]
                
        pktlist = []
        # We only need to look at the first 6 packets for this test
        for i in range(1, 7):
            pkt = pkts.next()
            pktlist.append(pkt)

        #print pktlist
        
        self.failUnless(pktlist == pktlistref)
Esempio n. 12
0
 def testPySharkBadDecodeAs2(self):
     try:
         pkts = pyshark.iter(self.filename, ['frame.number', 'eth.type'],
                             '', '')
         self.fail("Bad Decode As string did not raise TypeError")
     except PySharkError:
         pass
Esempio n. 13
0
 def testPySharkBadDisplayFilter(self):
     try:
         pkts = pyshark.iter(self.filename,
                             ['frame.number', 'eth.type'],
                             55)
         self.fail("Bad Display Filter did not raise TypeError")
     except TypeError:
         pass
Esempio n. 14
0
 def testPySharkIterator2(self):
     pkts = pyshark.iter(self.filename,
                         ['frame.number', 'eth.type'],
                         '')
     count = 0
     for pkt in pkts:
         count += 1
     self.failUnless(count == 100)
Esempio n. 15
0
 def testPySharkFilenameDoesntExist1(self):
     """This should fail because the file doesn't exist"""
     try:
         pkts = pyshark.iter("thisfiledoesntexist.pcap",
                             ['frame.number', 'eth.type'], '')
         self.fail("Bad Filename did not raise PySharkError")
     except PySharkError:
         pass
Esempio n. 16
0
 def testPySharkBadFieldNames2(self):
     """This shoudl fail because one of the list items in the
     second argument is not a string"""
     try:
         pkts = pyshark.iter(self.filename, ['frame.number', 4, 'eth.type'],
                             '')
         self.fail("Bad Field Names did not raise TypeError")
     except TypeError:
         pass
Esempio n. 17
0
 def testPySharkBadDecodeAs1(self):
     try:
         pkts = pyshark.iter(self.filename,
                             ['frame.number', 'eth.type'],
                             '',
                             'rtcp.port==80,ftp')
         self.fail("Bad Decode As string did not raise TypeError")
     except PySharkError:
         pass
Esempio n. 18
0
 def testPySharkDisplayFilter(self):
     """There are 74 UDP packets in the capture"""
     pkts = pyshark.iter(self.filename,
                         ['frame.number', 'eth.type'],
                         'udp')
     count = 0
     for pkt in pkts:
         count += 1
     self.failUnless(count == 74)
Esempio n. 19
0
 def testPySharkBadFilename1(self):
     """This should fail because the first argument is a number"""
     try:
         pkts = pyshark.iter(34,
                             ['frame.number', 'eth.type'],
                             '')
         self.fail("Bad Filename did not raise TypeError")
     except TypeError:
         pass
Esempio n. 20
0
 def testPySharkBadFilename2(self):
     """This should fail because the filename is None"""
     try:
         pkts = pyshark.iter(None,
                             ['frame.number', 'eth.type'],
                             '')
         self.fail("Bad Filename did not raise TypeError")
     except TypeError:
         pass
Esempio n. 21
0
 def testPySharkBadFieldNames1(self):
     """This should fail because the second argument is not a list"""
     try:
         pkts = pyshark.iter(self.filename,
                             3,
                             '')
         self.fail("Bad Field Names did not raise TypeError")
     except TypeError:
         pass
Esempio n. 22
0
 def testPySharkFilenameDoesntExist3(self):
     """This should fail because the filename is an empty string"""
     try:
         pkts = pyshark.iter("",
                             ['frame.number', 'eth.type'],
                             '')
         self.fail("Bad Filename did not raise PySharkError")
     except PySharkError:
         pass
Esempio n. 23
0
 def testPySharkFilenameDoesntExist1(self):
     """This should fail because the file doesn't exist"""
     try:
         pkts = pyshark.iter("thisfiledoesntexist.pcap",
                             ['frame.number', 'eth.type'],
                             '')
         self.fail("Bad Filename did not raise PySharkError")
     except PySharkError:
         pass
Esempio n. 24
0
 def testPySharkBadFieldNames2(self):
     """This shoudl fail because one of the list items in the
     second argument is not a string"""
     try:
         pkts = pyshark.iter(self.filename,
                             ['frame.number', 4, 'eth.type'],
                             '')
         self.fail("Bad Field Names did not raise TypeError")
     except TypeError:
         pass
Esempio n. 25
0
    def testAselTrueFieldsTrue(self):
        """allowSingleElementLists(True) and showEmptyFields(True)"""
        pkts = pyshark.iter(self.filename, [
            'tcp.dstport', 'frame.number', 'arp.hw.type', 'udp.srcport',
            'tcp.srcport'
        ], '')

        pkts.allowSingleElementLists(True)
        pkts.showEmptyFields(True)

        pktlistref = [{
            'frame.number': [1],
            'tcp.srcport': [],
            'tcp.dstport': [],
            'arp.hw.type': [],
            'udp.srcport': [60000]
        }, {
            'frame.number': [2],
            'tcp.srcport': [],
            'tcp.dstport': [],
            'arp.hw.type': [],
            'udp.srcport': [60000]
        }, {
            'frame.number': [3],
            'tcp.srcport': [],
            'tcp.dstport': [],
            'arp.hw.type': [1],
            'udp.srcport': []
        }, {
            'frame.number': [4],
            'tcp.srcport': [],
            'tcp.dstport': [],
            'arp.hw.type': [1],
            'udp.srcport': []
        }, {
            'frame.number': [5],
            'tcp.srcport': [],
            'tcp.dstport': [],
            'arp.hw.type': [1],
            'udp.srcport': []
        }, {
            'frame.number': [6],
            'tcp.srcport': [],
            'tcp.dstport': [],
            'arp.hw.type': [],
            'udp.srcport': [60000]
        }]

        pktlist = []
        for i in range(1, 7):
            pkt = pkts.next()
            pktlist.append(pkt)

        #print pktlist
        self.failUnless(pktlist == pktlistref)
Esempio n. 26
0
    def testAselFalseFieldsTrue(self):
        """allowSingleElementLists(False) and showEmptyFields(True)"""
        pkts = pyshark.iter(self.filename, [
            'tcp.dstport', 'frame.number', 'arp.hw.type', 'udp.srcport',
            'tcp.srcport'
        ], '')

        pkts.allowSingleElementLists(False)
        pkts.showEmptyFields(True)

        pktlistref = [{
            'frame.number': 1,
            'tcp.srcport': None,
            'tcp.dstport': None,
            'arp.hw.type': None,
            'udp.srcport': 60000
        }, {
            'frame.number': 2,
            'tcp.srcport': None,
            'tcp.dstport': None,
            'arp.hw.type': None,
            'udp.srcport': 60000
        }, {
            'frame.number': 3,
            'tcp.srcport': None,
            'tcp.dstport': None,
            'arp.hw.type': 1,
            'udp.srcport': None
        }, {
            'frame.number': 4,
            'tcp.srcport': None,
            'tcp.dstport': None,
            'arp.hw.type': 1,
            'udp.srcport': None
        }, {
            'frame.number': 5,
            'tcp.srcport': None,
            'tcp.dstport': None,
            'arp.hw.type': 1,
            'udp.srcport': None
        }, {
            'frame.number': 6,
            'tcp.srcport': None,
            'tcp.dstport': None,
            'arp.hw.type': None,
            'udp.srcport': 60000
        }]

        pktlist = []

        for i in range(1, 7):
            pkt = pkts.next()
            pktlist.append(pkt)

        self.failUnless(pktlist == pktlistref)
Esempio n. 27
0
    def testWildcardAselFalseFieldsFalse(self):
        """Wildcard version of allowSingleElementLists(False) and showEmptyFields(False)"""
        pkts = pyshark.iter(self.filename, [
            'tcp.dstport', 'udp.*', 'arp.hw.type', 'udp.srcport', 'tcp.srcport'
        ], '')

        pkts.allowSingleElementLists(False)
        pkts.showEmptyFields(False)

        pktlistref = [{
            'udp.checksum_coverage': 9,
            'udp.length': 9,
            'udp.checksum_bad': False,
            'udp.checksum': 5072,
            'udp.dstport': 60000,
            'udp.srcport': 60000,
            'udp.port': [60000, 60000],
            'udp.checksum_good': True
        }, {
            'udp.checksum_coverage': 9,
            'udp.length': 9,
            'udp.checksum_bad': False,
            'udp.checksum': 5077,
            'udp.dstport': 60000,
            'udp.srcport': 60000,
            'udp.port': [60000, 60000],
            'udp.checksum_good': True
        }, {
            'arp.hw.type': 1
        }, {
            'arp.hw.type': 1
        }, {
            'arp.hw.type': 1
        }, {
            'udp.checksum_coverage': 9,
            'udp.length': 9,
            'udp.checksum_bad': False,
            'udp.checksum': 5086,
            'udp.dstport': 60000,
            'udp.srcport': 60000,
            'udp.port': [60000, 60000],
            'udp.checksum_good': True
        }]

        pktlist = []
        # We only need to look at the first 6 packets for this test
        for i in range(1, 7):
            pkt = pkts.next()
            pktlist.append(pkt)

        #print pktlist

        self.failUnless(pktlist == pktlistref)
Esempio n. 28
0
 def testPySharkIterator(self):
     """capture1.pcap has 100 packets in it; 74 are udp packets
     """
     pkts = pyshark.iter(self.filename,
                         ['frame.number', 'eth.trailer', 'udp.srcport'], '')
     count = 0
     udpcount = 0
     for pkt in pkts:
         count += 1
         if ("udp.srcport" in pkt and pkt["udp.srcport"] not in [None, []]):
             #print pkt
             udpcount += 1
     self.failUnless(count == 100)
     self.failUnless(udpcount == 74)
Esempio n. 29
0
 def testPySharkIterator(self):
     """capture1.pcap has 100 packets in it; 74 are udp packets
     """
     pkts = pyshark.iter(self.filename,
                         ['frame.number', 'eth.trailer', 'udp.srcport'],
                         '')
     count = 0
     udpcount = 0 
     for pkt in pkts:
         count += 1
         if("udp.srcport" in pkt and pkt["udp.srcport"] not in [None, []]):
             #print pkt
             udpcount += 1
     self.failUnless(count == 100)
     self.failUnless(udpcount == 74)
Esempio n. 30
0
    def testAselFieldMethodToggling(self):
        """Make sure toggling works"""

        pkts = pyshark.iter(self.filename,
                            ['tcp.dstport', 'frame.number', 'arp.hw.type', 'udp.srcport', 'tcp.srcport'],
                            '')

        pkts.allowSingleElementLists(False)
        self.failUnless(pkts.allowSingleElementLists() == False)
        pkts.allowSingleElementLists(True)
        self.failUnless(pkts.allowSingleElementLists() == True)
        pkts.allowSingleElementLists(False)
        self.failUnless(pkts.allowSingleElementLists() == False)

        pkts.showEmptyFields(False)
        self.failUnless(pkts.showEmptyFields() == False)
        pkts.showEmptyFields(True)
        self.failUnless(pkts.showEmptyFields() == True)
        pkts.showEmptyFields(False)
        self.failUnless(pkts.showEmptyFields() == False)
Esempio n. 31
0
 def tefstPySharkCrazyStuff(self):
     """Crazy"""
     pkts = pyshark.iter(self.filename,
                         #['frame.number', 'eth.type', 'udp.srcport', 'tcp.srcport'],
                         ['frame.number', 'arp.hw.type', 'udp.srcport'],
                         '')
     print dir(pkts)
     print pkts.allowSingleElementLists.__doc__
     print "default = %s" % pkts.allowSingleElementLists()
     print "changing...%s" % pkts.allowSingleElementLists(False)
     print "changed = %s" % pkts.allowSingleElementLists()
     print "default = %s" % pkts.showEmptyFields()
     print "changing...%s" % pkts.showEmptyFields(False)
     print "changed = %s" % pkts.showEmptyFields()
     count = 0
     print pkts.next()
     print pkts.next()
     print pkts.next()
     print pkts.next()
     print pkts.next()
     print pkts.next()
Esempio n. 32
0
    def testAselFieldMethodToggling(self):
        """Make sure toggling works"""

        pkts = pyshark.iter(self.filename, [
            'tcp.dstport', 'frame.number', 'arp.hw.type', 'udp.srcport',
            'tcp.srcport'
        ], '')

        pkts.allowSingleElementLists(False)
        self.failUnless(pkts.allowSingleElementLists() == False)
        pkts.allowSingleElementLists(True)
        self.failUnless(pkts.allowSingleElementLists() == True)
        pkts.allowSingleElementLists(False)
        self.failUnless(pkts.allowSingleElementLists() == False)

        pkts.showEmptyFields(False)
        self.failUnless(pkts.showEmptyFields() == False)
        pkts.showEmptyFields(True)
        self.failUnless(pkts.showEmptyFields() == True)
        pkts.showEmptyFields(False)
        self.failUnless(pkts.showEmptyFields() == False)
Esempio n. 33
0
 def tefstPySharkCrazyStuff(self):
     """Crazy"""
     pkts = pyshark.iter(
         self.filename,
         #['frame.number', 'eth.type', 'udp.srcport', 'tcp.srcport'],
         ['frame.number', 'arp.hw.type', 'udp.srcport'],
         '')
     print dir(pkts)
     print pkts.allowSingleElementLists.__doc__
     print "default = %s" % pkts.allowSingleElementLists()
     print "changing...%s" % pkts.allowSingleElementLists(False)
     print "changed = %s" % pkts.allowSingleElementLists()
     print "default = %s" % pkts.showEmptyFields()
     print "changing...%s" % pkts.showEmptyFields(False)
     print "changed = %s" % pkts.showEmptyFields()
     count = 0
     print pkts.next()
     print pkts.next()
     print pkts.next()
     print pkts.next()
     print pkts.next()
     print pkts.next()
Esempio n. 34
0
 def testPySharkIterator2(self):
     pkts = pyshark.iter(self.filename, ['frame.number', 'eth.type'], '')
     count = 0
     for pkt in pkts:
         count += 1
     self.failUnless(count == 100)
Esempio n. 35
0
 def testPySharkIteratorWildcard1(self):
     pkts = pyshark.iter(self.filename, ['*'], '')
     count = 0
     num_keys = len(pkts.next().keys())
     self.failUnless(num_keys == 55)
Esempio n. 36
0
 def testPySharkIteratorWildcard3(self):
     pkts = pyshark.iter(self.filename, ['ip.*', 'eth.type'], '')
     count = 0
     num_keys = len(pkts.next().keys())
     self.failUnless(num_keys == 25)
Esempio n. 37
0
 def testPySharkBadDecodeAs3(self):
     pkts = pyshark.iter(self.filename,
                         ['frame.number', 'eth.type'],
                         '',
                         'tcp.port==80,ftp')
     del pkts
Esempio n. 38
0
 def testPySharkBadDecodeAs3(self):
     pkts = pyshark.iter(self.filename, ['frame.number', 'eth.type'], '',
                         'tcp.port==80,ftp')
     del pkts