def recive(self, ethernet_frame): ip_packet = IPPacket() ip_packet.decode(ethernet_frame.payload) if ip_packet.destination == ip_address: if ip_packet.protocol == ICMP_PROTOCOL: icmp_handler.recive(ip_packet) elif ip_packet.protocol == TCP_PROTOCOL: tcp_handler.recive(ip_packet) elif ip_packet.protocol == UDP_PROTOCOL: udp_handler.recive(ip_packet)
from binascii import unhexlify from pynetstack.datastructs import EthernetFrame, IPPacket from pynetstack.tests.utils import print_object data = unhexlify('002129994adce4115b2ca6d8080045000034e3084000400627bac0a80274cc02a0e2c7f100505b5ae554ee9f1067801007c7302800000101080a0008715f3ab2baa3') ethernet_frame = EthernetFrame() ethernet_frame.decode(data) print_object(ethernet_frame) packet = IPPacket() packet.decode(ethernet_frame.payload) print_object(packet) """ encoded = frame.encode() if ethernet_frame.payload[:28] == encoded: print 'encoding ok' else: print 'encoding failed' """