def test_readUDP(self): TESTDATA_FILENAME = os.path.join(os.path.dirname(__file__), 'test_input.pcap') p = pcap.Pcap(TESTDATA_FILENAME) p.readGlobalHeader() mypcaprecord = p.readAPacket() e = Ethernet.Ethernet() e.regress = False e.unpack(mypcaprecord.packet) self.assertEqual(e.srcmac, 0x0018f8b84454) self.assertEqual(e.dstmac, 0xe0f847259336) self.assertEqual(e.type, 0x0800) i = IP() i.regress = False i.unpack(e.payload) self.assertEqual(i.dstip, "192.168.1.110") self.assertEqual(i.srcip, "213.199.179.165") self.assertEqual(i.protocol, 0x6) self.assertEqual(i.ttl, 48) self.assertEqual(i.flags, 0x2) self.assertEqual(i.id, 0x4795) self.assertEqual(i.len, 56) self.assertEqual(i.dstip, 3232235886) self.assertEqual(i.srcip, 3586634661) p.close()
def test_readUDP(self): TESTDATA_FILENAME = os.path.join(os.path.dirname(__file__), 'test_input.pcap') p = pcap.Pcap(TESTDATA_FILENAME) p.readGlobalHeader() mypcaprecord = p.readAPacket() e = Ethernet.Ethernet() e.regress = False e.unpack(mypcaprecord.packet) self.assertEqual(e.srcmac,0x0018f8b84454) self.assertEqual(e.dstmac,0xe0f847259336) self.assertEqual(e.type,0x0800) i = IP() i.regress = False i.unpack(e.payload) self.assertEqual(i.dstip,"192.168.1.110") self.assertEqual(i.srcip,"213.199.179.165") self.assertEqual(i.protocol,0x6) self.assertEqual(i.ttl,48) self.assertEqual(i.flags,0x2) self.assertEqual(i.id,0x4795) self.assertEqual(i.len,56) self.assertEqual(i.dstip,3232235886) self.assertEqual(i.srcip,3586634661) p.close()
def test_basicIP(self): i = IP() i.dstip = "235.0.0.1" i.srcip = "192.168.1.1" i.payload = struct.pack(">H",0xa5) ippayload = i.pack() i2 = IP() i2.regress = False i2.unpack(ippayload) self.assertEqual(i2.srcip,"192.168.1.1") self.assertEqual(i2.dstip,"235.0.0.1") self.assertEqual(i2.payload,struct.pack(">H",0xa5))
def test_basicIP(self): i = IP() i.dstip = "235.0.0.1" i.srcip = "192.168.1.1" i.payload = struct.pack(">H", 0xa5) ippayload = i.pack() i2 = IP() i2.regress = False i2.unpack(ippayload) self.assertEqual(i2.srcip, "192.168.1.1") self.assertEqual(i2.dstip, "235.0.0.1") self.assertEqual(i2.payload, struct.pack(">H", 0xa5))
def test_defaultIP(self): i = IP() self.assertRaises(ValueError, lambda: i.pack())
def test_unpackIPShort(self): i = IP() dummypayload = struct.pack('H', 0xa5) self.assertRaises(ValueError, lambda: i.unpack(dummypayload))
def test_defaultIP(self): i = IP() self.assertRaises(ValueError, lambda : i.pack())
def test_unpackIPShort(self): i = IP() dummypayload = struct.pack('H',0xa5) self.assertRaises(ValueError, lambda : i.unpack(dummypayload))