问题
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