Packet building with Scapy and Gevent

无人久伴 提交于 2020-01-05 08:54:23

问题


I'm trying to write a program, which works multithread using gevent.

The program will generate a packet, build it with scapy and then send it using raw_socket. Like so:

def worker(...):
    s = socket.socket(socket.AF_PACKET, socket.SOCK_RAW)
    s.bind((iface, socket.htons(0x0800)))
    packet = fragment(Ether()/IP(dst=dst, src=str(src))/TCP(dport=dport, sport=sport)/pay_load, fragsize=100)
    data = [piece.build() for piece in packet]
    for packet in data:
        s.send(packet)

The code run just fine in sequence, but when I spawn the thread using gevent, it'll fail at [piece.build() for piece in packet] with "WARNING: Child died unexpectedly. Packets may have not been sent 30405".

The best guess I can do is somehow Packet.build in Scapy does not work under threading. Can anybody help for a workaround or another way to generate packet?

来源:https://stackoverflow.com/questions/17874278/packet-building-with-scapy-and-gevent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!