async def recv(self): rx_frame = await self.sink.recv() eth = Ether() eth.dst = rx_frame.eth_dest_mac.integer.to_bytes(6, 'big') eth.src = rx_frame.eth_src_mac.integer.to_bytes(6, 'big') eth.type = rx_frame.eth_type.integer arp = ARP() arp.hwtype = rx_frame.arp_htype.integer arp.ptype = rx_frame.arp_ptype.integer arp.hwlen = rx_frame.arp_hlen.integer arp.plen = rx_frame.arp_plen.integer arp.op = rx_frame.arp_oper.integer arp.hwsrc = rx_frame.arp_sha.integer.to_bytes(6, 'big') arp.psrc = rx_frame.arp_spa.integer arp.hwdst = rx_frame.arp_tha.integer.to_bytes(6, 'big') arp.pdst = rx_frame.arp_tpa.integer rx_pkt = eth / arp return Ether(bytes(rx_pkt))
def getARPPacket(self): """ 构造ARP数据包 :return: """ try: arp_packet = ARP() arp_packet.hwtype = int(self.entries[0].get()) arp_packet.ptype = int(self.entries[1].get()) arp_packet.op = int(self.entries[2].get()) arp_packet.hwlen = int(self.entries[3].get()) arp_packet.plen = int(self.entries[4].get()) arp_packet.hwdst = self.entries[5].get() arp_packet.psrc = self.entries[6].get() arp_packet.hwsrc = self.entries[7].get() arp_packet.pdst = self.entries[8].get() arp_packet.show() self.resultText.insert('end', arp_packet.summary() + '\n') self.resultText.insert('end', str(arp_packet) + '\n') return Ether() / arp_packet except Exception as e: print(e.with_traceback()) finally: pass