def send(self, payload, protocol, target_mac): frame = EthernetFrame() frame.source = mac_address frame.destination = target_mac frame.payload = payload frame.protocol = protocol write_callback(frame)
def recive(self, data): frame = EthernetFrame() frame.decode(data) if frame.protocol == IP_PROTOCOL: ip_handler.recive(frame) elif frame.protocol == ARP_PROTOCOL: arp_handler.recive(frame) else: print '%s packet from %s to %s' % (hex(frame.protocol), hex(frame.source), hex(frame.destination))
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' """
from binascii import hexlify, unhexlify from pynetstack.datastructs import EthernetFrame from pynetstack.tests.utils import print_object data = unhexlify('ffffffffffff14dae94c72670806000108000604000114dae94c7267c0a80266000000000000c0a802fa000000000000000000000000000000000000') frame = EthernetFrame() frame.decode(data) print_object(frame) encoded = frame.encode() print hexlify(encoded) if data == encoded: print 'encoding ok' else: print 'encoding failed'