Пример #1
0
 def recive(self, ethernet_frame):
     
     
     arp_packet = ARPPacket()
     arp_packet.decode(ethernet_frame.payload)
     
     print 'arp packet from %s to %s (%s)' % (hex(ethernet_frame.source), hex(ethernet_frame.destination), int_to_ip(arp_packet.target_ip))
     
     if arp_packet.target_ip == ip_address:
         arp_response = ARPPacket()
         arp_response.hw_type = 1
         arp_response.proto_type = 0x800
         arp_response.hw_size = 6
         arp_response.proto_size = 4
         arp_response.opcode = 2
         arp_response.sender_mac = mac_address
         arp_response.sender_ip = ip_address
         arp_response.target_mac = arp_packet.sender_mac
         arp_response.target_ip = arp_packet.sender_ip
         
         ethernet_handler.send(arp_response.encode(), ARP_PROTOCOL, arp_packet.sender_mac)
Пример #2
0
from binascii import unhexlify

from pynetstack.datastructs import ARPPacket
from pynetstack.tests.utils import print_object
from datastructs import EthernetFrame


data = unhexlify('ffffffffffff14dae94c72670806000108000604000114dae94c7267c0a80266000000000000c0a802fa000000000000000000000000000000000000')

ethernet_frame = EthernetFrame()
ethernet_frame.decode(data)

frame = ARPPacket()
frame.decode(ethernet_frame.payload)

print_object(frame)

encoded = frame.encode()

if ethernet_frame.payload[:28] == encoded:
    print 'encoding ok'
else:
    print 'encoding failed'