ethernet_frame.py 922 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. import socket
  2. import sys
  3. import net_params
  4. net = net_params.LocalNetwork()
  5. interface = net.get_default_interface()
  6. ethernet_frame = bytearray([
  7. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, # Destination MAC (broadcast)
  8. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, # Source MAC
  9. 0x12, 0x34, # Custom EtherType (0x1234)
  10. # Payload (just some test data)
  11. 0xde, 0xad, 0xbe, 0xef # Example payload
  12. ])
  13. # 00:11:22:33:44:55
  14. def send_raw_frame():
  15. with socket.socket(socket.AF_PACKET, socket.SOCK_RAW) as raw_socket:
  16. print(raw_socket)
  17. print(f"Binding to interface: {interface}")
  18. raw_socket.bind((interface, socket.ETH_P_ALL))
  19. print("Sending raw packet")
  20. bytes_send = raw_socket.send(ethernet_frame)
  21. print(f"Send {bytes_send} bytes to the interface")
  22. def main():
  23. send_raw_frame()
  24. if __name__ == '__main__':
  25. main()