class ArpPacket(AbstractPacket): ''' classdocs ''' def __init__(self, context): self.__defaults = {'htype' : '0x1', 'ptype' : '0x800', 'hlen' : '0x6', 'plen' : '0x4', 'oper' : '0x1', 'sha' : '01:02:03:04:05:06', 'spa' : '192.168.0.1', 'tha' : '11:22:33:44:55:55', 'tpa' : '192.168.0.2'} context.update(self.__defaults) self.__context = context self.__common = PacketSenderCommon() def getHtype(self): return self.__common.hexStr2int_16_networkOrder(self.__context['htype']) def getPtype(self): return self.__common.hexStr2int_16_networkOrder(self.__context['ptype']) def getHLen(self): return self.__common.hexStr2int_8_networkOrder(self.__context['hlen']) def getPLen(self): return self.__common.hexStr2int_8_networkOrder(self.__context['plen']) def getOp(self): return self.__common.hexStr2int_16_networkOrder(self.__context['oper']) def getSha(self): return self.__common.generateMAC(self.__context['sha']) def getSpa(self): return socket.inet_aton(self.__context['spa']) def getTha(self): return self.__common.generateMAC(self.__context['tha']) def getTpa(self): return socket.inet_aton(self.__context['tpa']) def generatePacket(self): result = "" result += self.getHtype() + self.getPtype() + self.getHLen() + self.getPLen() + self.getOp() + self.getSha() + self.getSpa() + self.getTha() + self.getTpa() return result
class EthernetPacket(AbstractPacket): """ classdocs """ def __init__(self, context): self.__defaults = { "src_mac": "01:02:03:04:05:06", "dst_mac": "01:02:03:04:05:06", "ether_type": "0x801", "tag": "", "payload": "\x80" * 42, } context.update(self.__defaults) self.__context = context self.__common = PacketSenderCommon() def getShortDescription(self): return "" def getOptions(self): return "" def getFullDescription(self): return "" def getDefaults(self): return "" def setOption(self, key, value): pass def __generateMAC(self, strValue): return self.__common.generateMAC(strValue) def __generateSourceMAC(self): return self.__generateMAC(self.__context["src_mac"]) def __generateDestMAC(self): return self.__generateMAC(self.__context["dst_mac"]) def __generateTag(self): return "" def __generatePacketType(self): return self.__common.hexStr2int_16_networkOrder(self.__context["ether_type"]) def __generatePayload(self): return self.__context["payload"] def __generateCRC(self, packet): return self.__common.hexString2crc32_networkOrder(packet) def generatePacket(self): resultPacket = ( self.__generateDestMAC() + self.__generateSourceMAC() + self.__generateTag() + self.__generatePacketType() + self.__generatePayload() ) resultPacket += self.__generateCRC(resultPacket) return resultPacket
class Packet_999(AbstractPacket): ''' classdocs ''' def __init__(self, context): self.__defaults = {'preamble' : 'DD:DD:DD:DD:DD:DD:DD:d5', 'sid' : '0xe001', 'tag' : '', 'payload' : "\x80" *2} context.update(self.__defaults) self.__context = context self.__common = PacketSenderCommon() def getShortDescription(self): return "" def getOptions(self): return "" def getFullDescription(self): return "" def getDefaults(self): return "" def setOption( self, key, value ): pass def generatePreamble(self, strValue): listOctets = strValue.split(':'); resultPreamble = "" for octet in listOctets: resultPreamble += (chr(int( octet, 16))) return resultPreamble def __generatePreamble(self): return self.generatePreamble(self.__context['preamble']) def __generateTag(self): return "" def __generatePacketSid(self): return self.__common.hexStr2int_16_networkOrder(self.__context['sid']) def __generatePayload(self): return self.__context['payload'] def __generateCRC(self, packet ): return self.__common.hexString2crc32_networkOrder(packet) def generatePacket(self): resultPacket = self.__generatePreamble() + \ self.__generatePacketSid() + \ self.__generateTag() + \ self.__generatePayload(); resultPacket += self.__generateCRC( resultPacket ); return resultPacket;