Hello,
I would like to send an Ethernet frame consisting of the preamble, the start of frame delimiter, and then some custom data (in other words, NOT the MAC destination / source, nor the rest of the typical format for an Ethernet frame).
I found a python script that looks like it works with Linux (AF_PACKET): https://gist.github.com/cslarsen/11339448
From further reading and trial and error, it seems that this needs modified to use the Berkley Packet Filter.
What changes need to be made? Note: this is for a personal project.
I'm pretty sure AF_INET is what I need.
I would like to send an Ethernet frame consisting of the preamble, the start of frame delimiter, and then some custom data (in other words, NOT the MAC destination / source, nor the rest of the typical format for an Ethernet frame).
I found a python script that looks like it works with Linux (AF_PACKET): https://gist.github.com/cslarsen/11339448
From further reading and trial and error, it seems that this needs modified to use the Berkley Packet Filter.
What changes need to be made? Note: this is for a personal project.
I'm pretty sure AF_INET is what I need.
Python:
"""Demonstrates how to construct and send raw Ethernet packets on the
network.
You probably need root privs to be able to bind to the network interface,
e.g.:
$ sudo python sendeth.py
"""
from socket import *
def sendeth(src, dst, eth_type, payload, interface = "eth0"):
"""Send raw Ethernet packet on interface."""
assert(len(src) == len(dst) == 6) # 48-bit ethernet addresses
assert(len(eth_type) == 2) # 16-bit ethernet type
s = socket(AF_PACKET, SOCK_RAW)
# From the docs: "For raw packet
# sockets the address is a tuple (ifname, proto [,pkttype [,hatype]])"
s.bind((interface, 0))
return s.send(src + dst + eth_type + payload)
if __name__ == "__main__":
print("Sent %d-byte Ethernet packet on eth0" %
sendeth("\xFE\xED\xFA\xCE\xBE\xEF",
"\xFE\xED\xFA\xCE\xBE\xEF",
"\x7A\x05",
"hello"))