How do i send an raw ethernet frame in python

走远了吗. 提交于 2019-11-30 15:21:18

thanks to the comments for this question, i managed to get a connection going with a server. all it took was changing the address family to af_packet in linux. then i binded it to my nic and sent it. it worked. thanks for the help people! here is some example code:

s = socket(AF_PACKET, SOCK_RAW)
s.bind(("en1", 0))
pckt = packet() #my class that initializes the raw hex
data = pckt.getpacket()
s.send(data)
message = s.recv(4096)
print s
print s.decode('hex')

It needs to be in linux or debian. to my knowldege it doesnt work in mac osx. idk about windows. if u have a mac use pycap or scapy, they work fine.

In answer to your question Andrew, here's an example:

This answer helped me get WoL working. In this case the data is:

preamble = bytearray((0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF))
MAC = bytearray((0x00, 0x14, 0x85, 0xa4, 0x73, 0xce))
data = PREAMBLE + 16*MAC
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!