Sometimes you just need to send raw Ethernet frames directly on the network.
Seriously, it has its uses: Perhaps you're constructing your own non-IP network
for research or performance, you need to interface with some weird device on
the local network, or you're just playing around for fun. I used it
extensively while researching use of OpenFlow with Mininet.
Anyway, here's how to do it from Python. You most likely need to run the
program as superuser, or else you won't be able to inject Ethernet frames on
the network interface card.
There really isn't anything to it. Just create a raw socket and paste the
bytes. The only thing to note is the argument to bind.
Here's a full example using IPv4 + ICMP PING REQ payload: