编译EXE文件的时候pcap编译不进去。 pyinstaller pcap pypcap 报错

时间:2021-09-19 16:53:48

如果生成的exe源码中有import pcap

那么你目标机上就要先装npcap 并勾选winpcap API。

然后就不出这个问题了。

暂时的办法是第一个exe不包含import pcap。自检npcap的安装状态。如果有npcap就打开第二个exe,这个就可以import pcap了。

并且pypcap 貌似只在win10上能用。

from scapy.all import *

pkts = sniff(prn=lambda x: x.sprintf("{IP:%IP.src% -> %IP.dst%\n}{Raw:%Raw.load%\n}"))

简单尝试scapy,也可以抓包,明天试试,如果打包顺利,就换一下抓包工具。

192.168.1.169 -> 172.217.160.106
b'\r\n\x85\x00\xb5\x12\x81\x8d,Q039\x05\x92\x84\x0fWm(>G5#\xd2!\xa0\x01\x05\x14CHLO\x12\x00\x00\x00PAD\x00\xd6\x03\x00\x00SNI\x00\xe8\x03\x00\x00VER\x00\xec\x03\x00\x00CCS\x00\xfc\x03\x00\x00MSPC\x00\x04\x00\x00UAID0\x04\x00\x00TCID4\x04\x00\x00PDMD8\x04\x00\x00SMHL<\x04\x00\x00ICSL@\x04\x00\x00CTIMH\x04\x00\x00NONPh\x04\x00\x00MIDSl\x04\x00\x00SCLSp\x04\x00\x00CSCTp\x04\x00\x00COPTt\x04\x00\x00CFCWx\x04\x00\x00SFCW|\x04\x00\x00----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------www.googleapis.comQ039\x01\xe8\x81`\x92\x92\x1a\xe8~\xed\x80\x86\xa2\x15\x82\x91d\x00\x00\x00Chrome/64.0.3282.119 Windows NT 10.0; Win64; x64\x00\x00\x00\x00X509\x01\x00\x00\x00\x1e\x00\x00\x00*i|Z\x00\x00\x00\x00\x1dp-\xed\x1e\rQ\x91\xba\xeaok]%\xb4\x0bS\xeb\xb9<te6\xc5\xf1j\xae\x11U\xc4\xf8Zd\x00\x00\x00\x01\x00\x00\x005RTO\x00\x00\xf0\x00\x00\x00`\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'

https://github.com/pyinstaller/pyinstaller/issues/3282

pyinstall 官方提交了问题。

https://*.com/questions/48678451/pyinstall-cannot-build-pypcap-in-windows-10-64bit

*也提交了问题。

按我的水平,只能等待了。

i try build exe with pyinstaller.

the test.py is
print('hello')

the warntest.txt
missing module named resource - imported by posix, D:\PythonTest\\test.py
missing module named posix - imported by os, D:\PythonTest\\test.py
missing module named _posixsubprocess - imported by subprocess, D:\PythonTest\\test.py
missing module named 'org.python' - imported by pickle, D:\PythonTest\\test.py, xml.sax
missing module named readline - imported by cmd, code, pdb, D:\PythonTest\\test.py
excluded module named _frozen_importlib - imported by importlib, importlib.abc, D:\PythonTest\\test.py
missing module named _frozen_importlib_external - imported by importlib._bootstrap, importlib, importlib.abc, D:\PythonTest\\test.py
missing module named _winreg - imported by platform, D:\PythonTest\\test.py
missing module named _scproxy - imported by urllib.request
missing module named java - imported by platform, D:\PythonTest\\test.py
missing module named 'java.lang' - imported by platform, D:\PythonTest\\test.py, xml.sax._exceptions
missing module named vms_lib - imported by platform, D:\PythonTest\\test.py
missing module named termios - imported by tty, D:\PythonTest\\test.py, getpass
missing module named grp - imported by shutil, tarfile, D:\PythonTest\\test.py
missing module named pwd - imported by posixpath, shutil, tarfile, http.server, webbrowser, D:\PythonTest\\test.py, netrc, getpass
missing module named _dummy_threading - imported by dummy_threading, D:\PythonTest\\test.py
missing module named org - imported by copy, D:\PythonTest\\test.py

dist test.exe work on some computer.

then i try add code with pypcap:
import pcap
pc = pcap.pcap()
for d,b in pc:
print(d,b)

pyinstaller test.py

the warntest.txt same old one. no missing pcap or pypcap.
missing module named resource - imported by posix, D:\PythonTest\\test.py
missing module named posix - imported by os, D:\PythonTest\\test.py
missing module named _posixsubprocess - imported by subprocess, D:\PythonTest\\test.py
missing module named org - imported by pickle, D:\PythonTest\\test.py
missing module named readline - imported by cmd, code, pdb, D:\PythonTest\\test.py
excluded module named _frozen_importlib - imported by importlib, importlib.abc, D:\PythonTest\\test.py
missing module named _frozen_importlib_external - imported by importlib._bootstrap, importlib, importlib.abc, D:\PythonTest\\test.py
missing module named _winreg - imported by platform, D:\PythonTest\\test.py
missing module named _scproxy - imported by urllib.request
missing module named java - imported by platform, D:\PythonTest\\test.py
missing module named 'java.lang' - imported by platform, D:\PythonTest\\test.py, xml.sax._exceptions
missing module named vms_lib - imported by platform, D:\PythonTest\\test.py
missing module named termios - imported by tty, D:\PythonTest\\test.py, getpass
missing module named grp - imported by shutil, tarfile, D:\PythonTest\\test.py
missing module named pwd - imported by posixpath, shutil, tarfile, http.server, webbrowser, D:\PythonTest\\test.py, netrc, getpass
missing module named _dummy_threading - imported by dummy_threading, D:\PythonTest\\test.py
missing module named 'org.python' - imported by copy, D:\PythonTest\\test.py, xml.sax

dist test.exe worked on my build computer.
the other computer prompt DLL load failed:

PS C:\Users\Jack\Desktop\dist\test> .\test.exe
hello
Traceback (most recent call last):
File "test.py", line 10, in <module>
File "D:\PythonEnvi\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 714, in load_module
ImportError: DLL load failed: 找不到指定的模块。
[2360] Failed to execute script test

the line 10 is :
import pcap

so i try other way :
pyinstaller.exe --hidden-import pcap test.py
pyinstaller.exe -p D:\PythonEnvi\Lib\site-packages --hidden-import pcap D:\PythonTest\\test.py

windows10 Home 64bit
python 3.63
pyinstaller 3.3.1
pypcap 1.20
npcap 0.98 installer
npcap sdd 0.1
Microsoft Visual C++ Build Tools 2015