sendit.handlers package

Submodules

sendit.handlers.arp_handler module

Creates class that listens and responds to ARP messages

class sendit.handlers.arp_handler.ARP_Handler(reply=True, mappings=None, send_down=None, recv_up=None)

Bases: sendit.handlers.handler.Handler

Creates class that listens and responds to ARP messages. Child class of Handler

Parameters:
  • reply (Boolean) – boolean of whether to answer ARP requests, defaults to True
  • mappings (dictionary with String keys and values, defaults to None) – dictionary mapping MAC addresses to IPv4 addressses defaults to None. Required if reply is True
  • send_queue (asyncio.Queue) – asyncio.Queue that will be used to put frames in to send
Raises:

ValueError – when reply is set to true but mappings is not defined or when keys in mappings are not valid IPv4 addresses or when values in mappings are not valid MAC addresses

listen()

listens and responds for ARP messages coming in on recv_queue, put there by an ethernet_handler

sendit.handlers.ethernet_handler module

Creates class that listens and responds to Layer2 Etherframes

class sendit.handlers.ethernet_handler.EtherFrame_Handler(send_up=None, send_down=None, recv_up=None, recv_down=None)

Bases: sendit.handlers.handler.Handler

Asynchronously listens for Etherframes in own queue placed there by Bytes_Handler Creates EtherFrames from raw bytes, places those in async queues based on MAC mappings in queue_mappings

Parameters:
  • send_up (Dictionary where keys are strings in format mac_protocol, values are lists of asyncio.queue, Dictionary where keys are strings in format mac_protocol, values are lists of asyncio.queue) – asyncio.Queue OR dictionary of queues to put items in to go to higher layers, dictionary mapping async queues to protocol names
  • send_down (asyncio.Queue) – asyncio.Queue to put items in to go to lower layers
  • recv_up (asyncio.Queue) – asyncio.Queue to receive items from higher layers
  • recv_down (asyncio.Queue) – asyncio.Queue to receive items from lower layers
add_queue(mac, queue)

Add a higher protocol layer queue into ethernet handler for management

Parameters:mac (String) – mac address to listen on
await_from_higher()

Wait for frames from higher layers that needs Ethernet Header adjusted Swaps src and destination

listen()

Asynchronously listen for etherframes put in self.recv_queue If the protocols in the frame match one of the keys in self.queue_mappings Pass that frame on to all queues in corresponding list

remove_protocol(protocol)

Remove protocol from list of protocols that handler will handler for

Parameters:protocol (String) – string of protocol to remove
remove_queue(mac, protocol)

Remove upper layer queue from Ethernet_Handler

Parameters:
  • mac (String) – string of mac address to remove corresponding handler
  • protocol (String) – protocol of handler to remove
Raises:

ValueError – if mac not valid MAC address

sendit.handlers.ipv4_handler module

Creates class that listens and responds to Layer 3 IPv4

class sendit.handlers.ipv4_handler.IPv4_Handler(send_up=None, send_down=None, recv_up=None, recv_down=None)

Bases: sendit.handlers.handler.Handler

IPv4 Handler that is child class of Handler

Parameters:send_up (asyncio.Queue or dictionary of asyncio.queues) – asyncio.Queue OR dictionary of queues to put items in to go to higher layers

:param send_down : asyncio.Queue to put items in to go to lower layers :type send_down: asyncio.Queue :param recv_up: asyncio.Queue to receive items from higher layers :type recv_up: asyncio.Queue :param recv_down: asyncio.Queue to receive items from lower layers :type recv_down: asyncio.Queue

await_from_higher()

Wait for frames from higher layers that needs IPv4 header adjusted Swaps src and destination and resets length and checksum

ip_fragmentation_handler(frame)

This pieces back together fragmented packets. This is a modified version of the algorithm defined in RFC 815 https://tools.ietf.org/html/rfc815

Parameters:frame (EtherFrame) – ethernet frame that contains fragmented packet
Returns:returns None if packet not completely defragmented, or IPv4 of defragged packet

:rtype:: IPv4 or None

listen()

Listens for frames coming in from queue, placed there by a Layer2 Handler If incoming frame contains IPv4 address destination contained in self.ips they are then passed to their respective higher level listeners Otherwise, they are discarded If frames come in with IPv4 fragmented, they are sent to ip_fragmentation_handler to be handled

sendit.handlers.ipv6_handler module

Creates class that listens and responds to Layer 3 IPv6

class sendit.handlers.ipv6_handler.IPv6_Handler(send_up=None, send_down=None, recv_up=None, recv_down=None)

Bases: sendit.handlers.handler.Handler

IPv6 Handler that is child class of Handler

Parameters:send_up (asyncio.Queue or dictionary of asyncio.queues) – asyncio.Queue OR dictionary of queues to put items in to go to higher layers

:param send_down : asyncio.Queue to put items in to go to lower layers :type send_down: asyncio.Queue :param recv_up: asyncio.Queue to receive items from higher layers :type recv_up: asyncio.Queue :param recv_down: asyncio.Queue to receive items from lower layers :type recv_down: asyncio.Queue

await_from_higher()

Wait for frames from higher layers that needs IPv6 header adjusted Swaps src and destination and resets length and checksum

listen()

Listen for frames coming in on queue to parse the IPv6 objects inside Asynchronous

sendit.handlers.raw_nic module

Set of classes that creates abstraction for dealing with raw_sockets

class sendit.handlers.raw_nic.Async_Raw_NIC(interface, send_up=None, recv_up=None)

Bases: sendit.handlers.handler.Handler

Child Class of Handler Creates Asynchronous Raw Socket, binds to provided interface Implements send method that works with rest of library

Parameters:
  • interface (String) – string name of network interface ex: eth0, wlan0. Not sure? Call ifconfig and look at interface names
  • queue (asyncio.Queue) – asyncio queue to send raw bytes too
  • queue – asyncio queue to receive outgoing bytes from
a_recv(n_bytes)

Asynchronously receive bytes

Parameters:n_bytes (int) – Number of bytes to receive
send(frame, n_bytes)

Overrides Socket send method Attempts to use as_bytes() method that is provided by all protocol classes in this library If not a class in this libary, calls str.encode on provided frame Them sends on raw socket

Parameters:frame (L2 object that has as_bytes function, such as Etherframe) – frame to send on Raw_NIC
sendall_from_queue()
class sendit.handlers.raw_nic.Raw_NIC(interface)

Bases: socket.socket

Child Class of Socket Creates Raw Socket, binds to provided interface Implements send method that works with rest of library

Parameters:interface (String) – string name of network interface ex: eth0, wlan0. Not sure? Call ifconfig and look at interface names
send(frame)

Overrides Socket send method Attempts to use as_bytes() method that is provided by all protocol classes in this library If not a class in this libary, calls str.encode on provided frame Them sends on raw socket

Parameters:frame (L2 object that has as_bytes function, such as Etherframe) – frame to send on Raw_NIC

sendit.handlers.udp_handler module

Creates class that listens and responds to Layer 4 UDP

class sendit.handlers.udp_handler.UDP_Handler(ports, send_up=None, send_down=None, recv_up=None, recv_down=None)

Bases: sendit.handlers.handler.Handler

Parameters:
  • ports (list of ints) –
    • list of ports to listen on
  • send_up (asyncio.Queue or dictionary of asyncio.queues) – asyncio.Queue OR dictionary of queues to put items in to go to higher layers

:param send_down : asyncio.Queue to put items in to go to lower layers :type send_down: asyncio.Queue :param recv_up: asyncio.Queue to receive items from higher layers :type recv_up: asyncio.Queue :param recv_down: asyncio.Queue to receive items from lower layers :type recv_down: asyncio.Queue

await_from_higher()

Wait for frames from higher layers that needs UDP header adjusted Swaps src and destination ports and ips (for checksum) and resets length and checksum

listen()

Listen for frames coming in on queue to parse the UDP objects inside

Parameters:queue (Queue object) – Queue to listen in on

Module contents