2017-07-17 81 views
1

我試圖效仿這裏的代碼:當我嘗試運行的代碼,Python的錯誤,在這條線Scapy and tcpreplay: bypass temporary file for performance混淆POPEN /標準輸入/ Scapy的/ tcpreplay

f = subprocess.Popen(argv, stdin=subprocess.PIPE) 

錯誤說

Failed: Error opening pcap file: truncated dump file; tried to read 4 file header bytes, only got 0 

我覺得我得到的錯誤,因爲子試圖之前的任何寫入標準輸入從標準輸入讀取。

有什麼建議嗎?

回答

0

得到它的工作......用這個頭而不是頭部在所列出的答案:

header = b'\xd4\xc3\xb2\xa1\x02\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\x7f\x00\x00\x01\x00\x00\x00' 

我最終沒有在我的代碼使用sendpfast。

爲了澄清我上面的問題......我試圖發送1個數據包,更新數據包的IP,然後在循環中發送更新的數據包。

將數據包列表寫入到stdin,然後使用sendpfast並沒有比寫入數據包到臨時文件,然後使用臨時文件上的sendpfast更快。 Sendpfast似乎只適用於從已經在磁盤上的pcap文件發送一堆數據包。

此鏈接(https://byt3bl33d3r.github.io/mad-max-scapy-improving-scapys-packet-sending-performance.html)爲我的問題提供了最佳解決方案。它允許我打開一個套接字,在該套接字上發送一個數據包,更新數據包,然後通過相同的套接字發送。