def test_ARP_packet_set_target_mac_addr(): raw_frame = b'"3DUfw\x00\x11"3DU\x08\x06\x00\x01\x08\x00\x06\x04\x00\x01\x00\x11"3DU\n\x14\x01\x01\x00\x00\x00\x00\x00\x00\n\x14\x01\x02' eth = ethernet.Ethernet_Frame(raw_frame) arp_packet = arp.ARP_packet(eth.data) arp_packet.target_mac_addr = b'\x55\x66\x77\x88\x99\xaa' assert arp_packet.packet.hex( ) == '00010800060400010011223344550a1401015566778899aa0a140102'
def test_ARP_packet_set_op(): raw_frame = b'"3DUfw\x00\x11"3DU\x08\x06\x00\x01\x08\x00\x06\x04\x00\x01\x00\x11"3DU\n\x14\x01\x01\x00\x00\x00\x00\x00\x00\n\x14\x01\x02' eth = ethernet.Ethernet_Frame(raw_frame) arp_packet = arp.ARP_packet(eth.data) arp_packet.op = b'\x05\x06' assert arp_packet.packet.hex( ) == '00010800060405060011223344550a1401010000000000000a140102'
def test_ARP_packet_set_sender_ip_addr(): raw_frame = b'"3DUfw\x00\x11"3DU\x08\x06\x00\x01\x08\x00\x06\x04\x00\x01\x00\x11"3DU\n\x14\x01\x01\x00\x00\x00\x00\x00\x00\n\x14\x01\x02' eth = ethernet.Ethernet_Frame(raw_frame) arp_packet = arp.ARP_packet(eth.data) arp_packet.sender_ip_addr = b'\x0b\x16\x01\x02' assert arp_packet.packet.hex( ) == '00010800060400010011223344550b1601020000000000000a140102'
def test_ARP_packet_set_prot_type(): raw_frame = b'"3DUfw\x00\x11"3DU\x08\x06\x00\x01\x08\x00\x06\x04\x00\x01\x00\x11"3DU\n\x14\x01\x01\x00\x00\x00\x00\x00\x00\n\x14\x01\x02' eth = ethernet.Ethernet_Frame(raw_frame) arp_packet = arp.ARP_packet(eth.data) arp_packet.prot_type = b'\x33\x44' assert arp_packet.packet.hex( ) == '00013344060400010011223344550a1401010000000000000a140102'
def test_ARP_packet_reply_packet(): raw_frame = b'"3DUfw\x00\x11"3DU\x08\x06\x00\x01\x08\x00\x06\x04\x00\x01\x00\x11"3DU\n\x14\x01\x01\x00\x00\x00\x00\x00\x00\n\x14\x01\x02' eth = ethernet.Ethernet_Frame(raw_frame) arp_packet = arp.ARP_packet(eth.data) assert arp_packet.conv_reply_packet() assert arp_packet.packet.hex( ) == '0001080006040002aabbccddeeff0a1401020011223344550a140101'
def test_ARP_packet_init(): raw_frame = b'"3DUfw\x00\x11"3DU\x08\x06\x00\x01\x08\x00\x06\x04\x00\x01\x00\x11"3DU\n\x14\x01\x01\x00\x00\x00\x00\x00\x00\n\x14\x01\x02' eth = ethernet.Ethernet_Frame(raw_frame) arp_packet = arp.ARP_packet(eth.data) # assert arp_packet.packet_all.hex() == '00010800060400010011223344550a1401010000000000000a140102' assert arp_packet.packet.hex( ) == '00010800060400010011223344550a1401010000000000000a140102' assert arp_packet.hard_type.hex() == '0001' assert arp_packet.prot_type.hex() == '0800' assert arp_packet.hard_size.hex() == '06' assert arp_packet.prot_size.hex() == '04' assert arp_packet.op.hex() == '0001' assert arp_packet.sender_mac_addr.hex() == '001122334455' assert arp_packet.sender_ip_addr.hex() == '0a140101' assert arp_packet.target_mac_addr.hex() == '000000000000' assert arp_packet.target_ip_addr.hex() == '0a140102'
def test_ARP_packet_init_dummy(): arp_packet = arp.ARP_packet() assert arp_packet.packet == b'\x00' * 28
# tun.up() print('Success') except: print('TAP up failure') sys.exit(ERROR) packetnumber = 0 try: while (True): raw_packet = tap.read(tap.mtu) # buf = tun.read(tun.mtu) eth_frame = eth.Ethernet_Frame(raw_packet) print(str(eth_frame)) if f.ETHER_TYPE[eth_frame.eth_type.hex()] == 'ARP': arp_packet = arp.ARP_packet(eth_frame.data) print(str(arp_packet)) if f.OP[arp_packet.op.hex()] == 'ARP_request': if arp_packet.conv_reply_packet(): eth_frame.src_mac_addr = arp_packet.sender_mac_addr eth_frame.dst_mac_addr = arp_packet.target_mac_addr eth_frame.data = arp_packet.packet print(str(arp_packet)) tap.write(eth_frame.frame) packetnumber += 1 except KeyboardInterrupt: tap.close()