from scapy.all import * from scapy.contrib.coap import CoAP import datetime import os # os.urandom() try: while True: # We wait for a packet with dst port 5683. # { print("Listening for Uplink Packet udp and port 5683"); uplink_rx = sniff(iface='eth1', count=1, filter="udp and port 5683"); print("Uplink packet received"); # Print packet uplink_rx[0].show(); print("Uplink packet hexdump"); hexdump(uplink_rx[0]) # } # # Paquete 1 # { print("Sending downlink packet: "); e = Ether(src="08:00:27:65:65:50", dst="0a:00:27:00:00:00") i = IPv6(src="fe80::a00:27ff:fe65:6550", dst="fe80::800:27ff:fe00:0") u = UDP(sport=10001,dport=10001) # c = CoAP(type='ACK', code='2.01 Created', token='ab', msg_id=0, options=[('Location-Path', 'storage'),(92, b'\xCA\xFE'), (92, b'\xBE\xAF\xBE\xAF\xBE\xAF\xBE\xAF\xBE\xAF\xBE\xAF\xBE\xAF\xBE\xAF\xBE\xAF\xBE\xAF')], paymark=b'\xff') c = CoAP(type='ACK', code='2.01 Created', token='ab', msg_id=0, options=[('Location-Path', 'storage')], paymark=b'\xff') # d = b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' p = e/i/u/c p.show() hexdump(p) sendp(p, iface="eth1") # } # # # We catch CTRL+C to stop the script. We need to capture # the interrupt outside of the loop and then ignore it. # { except KeyboardInterrupt: pass # }