Install Scapy for Mac OS Yosemite

It's not painful but it still requires a few steps. Here I log them.

First thing is to make sure you installed Python 2.x. Not sure about whether Python 3 has similar steps. Also, here I assume Homebrew is installed too. If any of the following codes result in a Permission denied error, append sudo in front the commands.

pip install scapy
pip install git+git://github.com/hellais/pypcap.git
brew install --with-python libdnet

After that, remember to configure the Homebrew's site-packeges so Python recognizes them. Below is an example. Detailed steps can be found above the summary in the terminal after running brew install ...

mkdir -p ~/Library/Python/2.7/lib/python/site-packages
echo 'import site; site.addsitedir("/usr/local/lib/python2.7/site-packages")' >> ~/Library/Python/2.7/lib/python/site-packages/homebrew.pth

Now you should be able to use Scapy.

Here is a piece of example code for DNS sniffing using Scapy.

from scapy.all import *

interface = 'en0'
filter_bpf = 'udp port 53'

def dns_sniff(pkt):
    print pkt.summary()

print "start" 
sniff(iface=interface, filter=filter_bpf, store=0, prn=dns_sniff)

2 comments

Leave a comment

Your email address will not be published. Required fields are marked *