2

I started to work on a python sniffer project. I want to use the pcap module but my computer always says "No module named pcap". I read that libpcap and pcap come with OS X but actually, it doesn't work...

I made a lot of research on the web and still unable tu run my python code. How am I supposed to do for running / linking or installing pcap ?

Note that I recently update to OSX Yosemite (but I didn't know if pcap worked before).

Quentin
  • 435
  • 2
  • 6
  • 15
  • `pip install pcap` or `easy_install pcap` – Andrew Jaffe Nov 26 '14 at 12:40
  • easy_install : `No local packages or download links found for pcap error: Could not find suitable distribution for Requirement.parse('pcap')` – Quentin Nov 26 '14 at 12:43
  • pip : `Could not find any downloads that satisfy the requirement pcap Some externally hosted files were ignored (use --allow-external pcap to allow). Cleaning up... No distributions at all found for pcap` – Quentin Nov 26 '14 at 12:45

2 Answers2

6
  1. Install brew from here
  2. Run brew doctor from terminal
  3. Solve the warnings from brew doctor results
  4. Run sudo easy_install pyrex
  5. Run sudo easy_install pypcap

=> This solved my problem (don't really know if brew is necessary)

Quentin
  • 435
  • 2
  • 6
  • 15
0

I think the library libpcap exists on OS X, but you are looking for a python module to which wraps it. I think the one you want is actually called pypcap, although I have no idea if that's the right/best one(*). You should be able to install it with either

easy_install pypcap

or

pip install pypcap

depending on the details of your python installation. (You also need to make sure that pip and/or easy_install are installing in a place known to the python installation that you're using; this may depend on which python it is -- Apple's, python.org, brew, etc. -- and how you've set it up.)

(*) I don't even know what pcap does, so note that there are a lot of pcap-related modules listed on PyPi.

Andrew Jaffe
  • 26,554
  • 4
  • 50
  • 59
  • I installed pypcap but the import line still return an error `No module named pcap`. Actually, what I want to do is just find the easiest way to sniff a TCP packet (with IP and port filtering), then extract the data that I'm interested in from the TCP payload... Notice that `import pypcap`doesn't work too. – Quentin Nov 26 '14 at 12:58