pythonpyinstallerscapy

Python, Scapy and exporting to an .exe


At the moment I play a little bit with scapy, Qt and python. So far everything worked fine when starting the programm with VSC. Now I tried to make an .exe with PyInstaller. It also worked, I got an .exe-file, can open it and get my Qt-Windows displayed. But when I use a scapy-function the program crashes without any message and the window get closed. I activated logging and find out, that the program crashed everytime we reaches following line of code:

ans, unans = sr(query, timeout=5)

With this line should be send a DNS-paket stored in the query-variable. And this step only fails in the exe.

These are my scapy-imports:

from scapy.layers.inet import IP, UDP
from scapy.layers.dns import DNS, DNSRR, DNSQR, DNSRROPT
from scapy.sendrecv import sr
from scapy.all import get_if_addr, conf

and this is my command-line for building the .exe:

-m PyInstaller --onefile -w --exclude=PySide6 --hidden-import=scapy.layers.dns --hidden-import=scapy.layers.inet --hidden-import=scapy.sendrecv --hidden-import=scapy.all
 --hidden-import=PyQt6 .\main.py

Anyone any idea? I'm very lost, its my first application where I try to build an exe..

Thanks a lot! Dennis


Solution

  • First, please delete -w and build the exe again.

    Second, open a cmd window, drag and drop the exe on it, and run the exe with Enter. Try the scapy function again and the error message should show up. drag and drop the exe

    At last, solve the error and build the exe still without -w. If there is no error showing up, then build the exe again with -w.

    If you have a problem solving the error, leave a comment or put the error in your question. I will update my answer, too.