2 minute read

I’m already dealing with a shark, now a python, too?!

Highlights

  • Built a basic Python program to capture packets using pyshark
  • Successfully performed remote network capture shown in a demo video
  • Gained better understanding of packet capture and remote network monitoring

The Long Story

I’m working with pyshark. It’s a wrapper for Wireshark’s tshark, a utility to dump and analyze traffic.

Using a virtual environment, venv, I installed Python 3.11 and used pip to install pyshark (and its dependencies came along for the ride, too). I originally installed Python 3.14 but saw issues in the pyshark Github about compatibility. I retreated to safer grounds in the form of a more mature version of Python.

This week I built the barebones of a Python program which can take in network packets from a Wireshark capture file, live network capture from the same machine, or remote capture using ssh on the same network. The last of these options I hadn’t planned on, but I felt as if it was a worthwhile feature as a way to monitor a local network.

I have a headless mac mini running Ubuntu that I can remote into from my main computer. Using the command line I am able to use the mac mini. My program can remote capture the network traffic from the mac mini through PyShark’s PipeCapture, a function that pipes output into my Python program so packets can be analyzed in near real-time (I say near as a caveat because of some latency that could be there). To test this, from my terminal on my main machine, I ping 8.8.8.8 and can see those packets written to a simple .txt file as well as printed out to the terminal on my main computer’s screen. Here’s a link to a working demo of remote capture: https://youtu.be/YZL313mTt5c. I didn’t hit my stretch goal of building a datatype Flow to track conversation, but I think I can still do it.

This week comes analysis! I will be building out the ability to count the number of times a protocol is seen, the frequency of ports used, byte totals, conversations (back and forth between source and destination), and other summaries of network traffic. These features will add context to what currently is just raw packet information.

I’m not seeing any upcoming impediments at the moment. I’d like to get working on my project update report early so it can serve as a review and forward-looking guide how to continue. I’m excited about the direction of this project, and I want to keep the momentum going.

I think building out tests for the features I plan and using test driven development practices would have helped me save time and maintain better focus in building. It’s tough when you get excited about building or to double down when trying to fix a bug instead of taking a step back and relying upon testing.