I want to send raw Ethernet data, kind of like netcat for Ethernet instead of TCP. What is the simplest way to do this on Unix? So far it looks like I need to write my own tool.
3 Answers
Pretty simple to achieve in Python, see Github: One way of sending raw Ethernet packets in Python
from socket import *
def sendeth(src, dst, eth_type, payload, interface = "eth0"):
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)
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"))
-
Thanks, I ended up using a Python script much like this one.jtpereyda– jtpereyda2016-11-16 17:39:46 +00:00Commented Nov 16, 2016 at 17:39
Does Scapy enought for you ? It allows you to build your own packets. → https://www.secdev.org/projects/scapy/
A simple way from the shell with widely used tools:
echo AA BB CC DD 00 50 AA BB CC DD 00 38 08 00 45 00 00 1C 00 01 00 00 40 11 E0 F6 C0 A8 8C 38 C0 A8 8C 50 1D 89 1D 83 00 08 2A F8 | xxd -r -p | socat - INTERFACE:eth0