8

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 3

5

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"))
1
  • Thanks, I ended up using a Python script much like this one. Commented Nov 16, 2016 at 17:39
1

Does Scapy enought for you ? It allows you to build your own packets. → https://www.secdev.org/projects/scapy/

1

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

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.