This is the complete explanation from the FreeBSD forum: Solved – [Python3.7 + Scapy] Class from Scapy is not found | The FreeBSD Forums
I started with installing FreeBSD 12.2 on a VirtualBox VM, set it up as a router (with IP Forwarding = 1 and ipfw firewall) with several ports needed (squid proxy and mpd for vpn). I’m going to use this router for my Cybersecurity class.
To help me teaching Cybersecurity, I need Python and Scapy module to do sniffing and spoofing. And this post is how I install Python and Scapy on FreeBSD 12.2.
Step 1. Install Python3.7. Okay, it’s true Python3.8 is recommended, however I still unable to install Scapy over Python3.8, since every time I try to install Scapy, it automatically assign itself to Python3.7.
# cd /usr/ports/lang/python37 # make install clean
Step 2. Install “pip” as Python Package. Previously I installed Scapy using its port (/usr/ports/net/scapy), however it didn’t work. It gave me an error message, saying:
$ python3.7 Python 3.7.9 (default, Apr 26 2021, 05:45:03) [Clang 10.0.1 ([email]firstname.lastname@example.org[/email]:llvm/llvm-project.git llvmorg-10.0.1-0-gef32c611a on freebsd12 Type "help", "copyright", "credits" or "license" for more information. >>> from scapy.all import * >>> a=IP() Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'IP' is not defined
So, based on my previous failure, I installed “pip” (Package Installer for Python), just like the Scapy documentation recommend:
# cd /usr/ports/devel/py-pip # make install clean
Step 3. Install Scapy using “pip”
# pip install --pre scapy
Now I can use Scapy inside Python3.7
# cd /usr/ports/devel/py-pip # make install clean # pip install --pre scapy
$ python3.7 Python 3.7.9 (default, May 6 2021, 04:34:40) [Clang 10.0.1 (email@example.com:llvm/llvm-project.git llvmorg-10.0.1-0-gef32c611a on freebsd12 Type "help", "copyright", "credits" or "license" for more information. >>> from scapy.all import * >>> a=IP() >>> a.show() ###[ IP ]### version = 4 ihl = None tos = 0x0 len = None id = 1 flags = frag = 0 ttl = 64 proto = ip chksum = None src = 127.0.0.1 dst = 127.0.0.1 \options \