Exemplo n.º 1
0
def dumpPacket(pkt, filePath, pktType=None):
    """Dump packet into file
		Input: (packet or dict) packet, must contain __str__ method
			(string) path to file
		Output: none
	"""
    # check directory
    dirPath = dirname(filePath)
    if not misc.checkDir(dirPath):
        error('Directory %s not available for logging' % dirPath)
        return

    # dump packet to file
    try:
        debug('Dumping packet to file:\n', filePath)
        file = open(filePath, 'a+')
        if pktType == PACKET_TYPE_ACCT:
            pktStr = misc.acctPacketToStr(pkt)
        elif pktType == PACKET_TYPE_AUTH:
            pktStr = misc.authPacketToStr(pkt)
        else:
            pktStr = misc.packetToStr(pkt)
        file.write(pktStr)
        file.close()
    except:
        error('Can not dump packet to file "%s"' % filePath)
        misc.printExceptionError()
Exemplo n.º 2
0
def dumpPacket(pkt, filePath, pktType = None):
	"""Dump packet into file
		Input: (packet or dict) packet, must contain __str__ method
			(string) path to file
		Output: none
	"""
	# check directory
	dirPath = dirname(filePath)
	if not misc.checkDir(dirPath):
		error('Directory %s not available for logging' % dirPath)
		return
		
	# dump packet to file
	try:
		debug ('Dumping packet to file:\n', filePath)
		file = open(filePath, 'a+')
		if pktType == PACKET_TYPE_ACCT:
			pktStr = misc.acctPacketToStr(pkt)
		elif pktType == PACKET_TYPE_AUTH:
			pktStr = misc.authPacketToStr(pkt)
		else:
			pktStr = misc.packetToStr(pkt)
		file.write(pktStr)
		file.close()
	except:
		error('Can not dump packet to file "%s"' % filePath)
		misc.printExceptionError()
Exemplo n.º 3
0
	def testPacketToStr(self):
		output = misc.packetToStr(self.auth_pkt)
		self.failUnless(isinstance(output, types.StringTypes))
		self.failUnless(output != '')
Exemplo n.º 4
0
	def testPacketToStr(self):
		output = misc.packetToStr(self.auth_pkt)
		self.failUnless(isinstance(output, types.StringTypes))
		self.failUnless(output != '')