import argparse import os import sys def process_pcap ( file_name ): print ( 'Opening. If your argparse knowledge needs a little brushing up, you can look at my argparse recipe book, or at any other of the dozens of tutorials on the web. Use the argparse module to get the pcap file name from the command line. This will also serve to check if your Python installation is OK. Step 1: Program skeletonīuild a skeleton for the program. In this post I use an example pcap file captured on my computer. The code below was written and executed on Linux (Linux Mint 18.3 64-bit), but the code is OS-agnostic it should work as well in other environments, with little or no modification. In this blog however I am restricting myself to regular Ethernet/IPv4/TCP packets, and I can just use scapy. Pyshark in particular is interesting because it simply leverages the underlying tshark installed on the system to do its work, so if you are in a situation where you need to leverage tshark’s powerful protocol decoding ability, pyshark is the way to go. Note that there are other alternative Python modules that can be used to read and parse pcap files, like pyshark and pycapfile. I will be using scapy, plus a few other modules that are not specific to packet processing or networking (argparse, pickle, pandas). Why Python? Apart from the well-known benefits of Python (open-source, relatively gentle learning curve, ubiquity, abundance of modules and so forth), it is also the case that Network Engineers are gaining expertise in this language and are using it in other areas of their work (device management and monitoring, workflow applications etc.). So, this is the topic of this blog post: how to go about programmatically processing packet capture (pcap) files. It is important to realize that we are not precluding the use of Wireshark for example, after your program locates the proverbial needle(s) in the haystack, you can use that information (say a packet number or a timestamp) in Wireshark to look at a specific point inside the pcap and gain more insight. In all these cases, it is immensely helpful to write a custom program to parse the pcaps and yield the data points you are looking for. Repeat the above exercises several times a week (or several times a day) with different sets of packet captures Prove that it is (or is not) because of the network. At some point the application server sporadically becomes slow (retransmits on both sides, TCP windows shrinking etc.). You are given two pcaps, one gathered on a SPAN port on an access switch, and another on an application server a few 元 hops away. In a pcap that captures thousands of TCP connections between a client and several servers, find the connections that were prematurely terminated because of a RST sent by the client at that point in time, determine how many other connections were in progress between that client and other servers Given a pcap that contains hundreds of thousands of packets, find the first connection to a particular server/service where the TCP SYN-ACK took more than 300ms to appear after the initial SYN There are situations, however, where the ability to process a pcap programmatically becomes extremely useful. And for good reason too - Wireshark provides an excellent GUI that not only displays the contents of individual packets, but also analysis and statistics tools that allow you to, for example, track individual TCP conversations within a pcap, and pull up related metrics. For most situations involving analysis of packet captures, Wireshark is the tool of choice.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |