1234567891011121314151617181920212223242526272829303132333435363738394041 |
- from scapy.packet import Raw
- import ID2TLib.PayloadGenerator as PayloadGenerator
- def add_padding(packet, bytes_padding = 0, user_padding=True):
- '''
- Adds padding to a packet with the given amount of bytes, but a maximum of 100 bytes.
- :param packet: the packet that will be extended with the additional payload
- :param bytes_padding: the amount of bytes that will be appended to the packet
- :return: the initial packet, extended with the wanted amount of bytes of padding
- '''
- if(user_padding and bytes_padding > 100):
- bytes_padding = 100
- payload = PayloadGenerator.generate_payload(bytes_padding)
- packet[Raw].load += Raw(load=payload).load
- return packet
- def equal_length(list_of_packets, length = 0):
- '''
- Equals the length of a given set of packets on the given length. If the given length is smaller than the largest
- packet, all the other packets are extended to the largest packet's length.
- :param list_of_packets: The given set of packet.
- :param length: The length each packet should have.
- :return: The set of extended packets.
- '''
- largest_packet = length
- for packet in list_of_packets:
- packet_length = len(packet)
- if(packet_length > largest_packet):
- largest_packet = packet_length
- for packet in list_of_packets:
- bytes_padding = largest_packet - len(packet)
- if(bytes_padding > 0):
- add_padding(packet, bytes_padding, False)
- return list_of_packets
|