Example #1
0
def make_arp_packet(sender_ip,
                    sender_mac,
                    target_ip,
                    target_mac='00:00:00:00:00:00',
                    op=ARP_OPERATION.REQUEST,
                    hardware_type='0x0001',
                    protocol='0x0800',
                    hardware_length='0x06',
                    protocol_length='0x04'):
    # Concatenate a byte string with the specified values.
    # For ARP format, see: https://tools.ietf.org/html/rfc826
    arp_packet = (hex_str_to_bytes(hardware_type) +
                  hex_str_to_bytes(protocol) +
                  hex_str_to_bytes(hardware_length) +
                  hex_str_to_bytes(protocol_length) + ARP_OPERATION(op) +
                  hex_str_to_bytes(sender_mac) + ipv4_to_bytes(sender_ip) +
                  hex_str_to_bytes(target_mac) + ipv4_to_bytes(target_ip))
    return arp_packet
Example #2
0
 def test__operation_enum__radd(self):
     self.expectThat(
         b"\xff" + bytes(ARP_OPERATION(ARP_OPERATION.REPLY)) + b"\xff",
         Equals(b"\xff\0\x02\xff"),
     )
Example #3
0
 def test__operation_enum__bytes(self):
     self.expectThat(bytes(ARP_OPERATION(ARP_OPERATION.REQUEST)),
                     Equals(b"\0\x01"))
     self.expectThat(bytes(ARP_OPERATION(ARP_OPERATION.REPLY)),
                     Equals(b"\0\x02"))
Example #4
0
 def test__operation_enum__str(self):
     self.expectThat(str(ARP_OPERATION(ARP_OPERATION.REQUEST)),
                     Equals("1 (request)"))
     self.expectThat(str(ARP_OPERATION(ARP_OPERATION.REPLY)),
                     Equals("2 (reply)"))
     self.expectThat(str(ARP_OPERATION(3)), Equals("3"))