def addPacket(self, parentPacket:AbstractPacket, childPacket:AbstractPacket): if(self.fromCounter.get(parentPacket.fromAddress) == None): self.counterFrom += 1 self.fromCounter.update({parentPacket.fromAddress:self.counterFrom}) if(self.fromCounter.get(parentPacket.toAddress) == None): self.toAddress += 1 self.toCounter.update({parentPacket.toAddress:self.toAddress}) if(self.fromCounter.get(childPacket.toPort) == None): self.toPort += 1 self.portOutCounter.update({childPacket.toPort:self.toPort}) if(self.fromCounter.get(childPacket.fromPort) == None): self.fromPort += 1 self.portInCounter.update({childPacket.fromPort:self.fromPort}) if(self.fromCounter.get(childPacket.getName()) == None): self.prName += 1 self.protocolStat.update({childPacket.getName():self.prName})
def parse(self): AbstractPacket.addMsg(AbstractPacket, 'Started Parsing IP packet') binIpHeader = self.binPacket[self.ethernetHeaderLength:self.ethernetHeaderLength + 20] ipHeader = unpack(self.UNPACK_FORMAT , binIpHeader) binVersion = ipHeader[0] self.version = binVersion >> 4 headerLengthBin = binVersion & 0xF self.iphLength = headerLengthBin * 4 self.ttl = ipHeader[5] self.protocol = ipHeader[6] self.fromAddress = str(socket.inet_ntoa(ipHeader[8])); self.toAddress = str(socket.inet_ntoa(ipHeader[9])); AbstractPacket.addMsg(AbstractPacket, 'Parsed IP packet from: ' + self.fromAddress + ' to: ' + self.toAddress)
def parse(self): AbstractPacket.addMsg(AbstractPacket, 'Started Parsing ICMP packet') binUdpHeader = self.binPacket[self.headerMargin:self.headerMargin + self.ICMP_HEADER_LENGTH] unpackedHeader = unpack(self.UNPACK_FORMAT, binUdpHeader) self.icmpType = str(unpackedHeader[0]) self.icmpCode = str(unpackedHeader[1]) self.icmpCheckSum = unpackedHeader[2] fullHeaderSize = self.headerMargin + self.ICMP_HEADER_LENGTH self.dataSize = len(self.binPacket) - fullHeaderSize # get data from the packet self.data = self.binPacket[fullHeaderSize:] AbstractPacket.addMsg(AbstractPacket, 'Parsed ICMP packet from port of type '+ self.icmpType) AbstractPacket.addMsg(AbstractPacket, 'ICMP-PACKET data:\n\n\n ' + str(self.data) +'\n\n')
def parse(self): AbstractPacket.addMsg(AbstractPacket, 'Started Parsing TCP packet') binTcpHeader = self.binPacket[self.headerMargin:self.headerMargin + self.TCP_HEADER_LENGTH] unpackedHeader = unpack(self.UNPACK_FORMAT, binTcpHeader) self.fromPort = str(unpackedHeader[0]) self.toPort = str(unpackedHeader[1]) self.sequence = unpackedHeader[2] self.acknowledgement = unpackedHeader[3] self.doffReserved = unpackedHeader[4] self.tcpHeaderLength = self.doffReserved >> 4 fullHeaderSize = self.headerMargin + self.tcpHeaderLength * 4 self.dataSize = len(self.binPacket) - fullHeaderSize # get data from the packet self.data = self.binPacket[fullHeaderSize:] AbstractPacket.addMsg(AbstractPacket, 'Parsed TCP packet from port: ' + self.fromPort + ' to: ' + self.toPort) AbstractPacket.addMsg(AbstractPacket, 'TCP-PACKET data:\n\n\n ' + AbstractPacket.getPrintable(str(self.data)) +'\n\n')
def parse(self): AbstractPacket.addMsg(AbstractPacket, 'Started Parsing UDP packet') binUdpHeader = self.binPacket[self.headerMargin:self.headerMargin + self.UDP_HEADER_LENGTH] unpackedHeader = unpack(self.UNPACK_FORMAT, binUdpHeader) self.fromPort = str(unpackedHeader[0]) self.toPort = str(unpackedHeader[1]) self.udpHeaderLength = unpackedHeader[2] self.udpCheckSum = unpackedHeader[3] fullHeaderSize = self.headerMargin + self.udpHeaderLength self.dataSize = len(self.binPacket) - fullHeaderSize # get data from the packet self.data = self.binPacket[fullHeaderSize:] AbstractPacket.addMsg(AbstractPacket, 'Parsed UDP packet from port: ' + self.fromPort + ' to: ' + self.toPort) AbstractPacket.addMsg(AbstractPacket, 'UDP-PACKET data:\n\n\n ' + str(self.data) +'\n\n')