pcap filter
- August 4th, 2010
- By Peter Bruderer
tcpdump and ngrep are both based on libpcap. Therefore both use the same filter expressions.
Here is the manual page of the pcap filter expression.
Posts Tagged ‘ pcap ’
tcpdump and ngrep are both based on libpcap. Therefore both use the same filter expressions.
Here is the manual page of the pcap filter expression.
Sometimes it is very practical to use grep, to find a specific regular expression in some files. It would also be very practical to have the grep functionality on the network. This feature is available.
Download ngrep. The package to get is ngrep-1.45.tar.bz2.
To get it to work on a mac do:
tar xvjf ngrep-1.45.tar.bz2 cd ngrep-1.45 ./configure --with-pcap-includes=/usr/include --prefix=/usr/local make sudo make install
To read the manual page you can run
man ngrep
Now run ngrep itself run
sudo ngrep <expression to find> <pcap filter expression>
<pcap filter expression> is used the same way as in tcdpdump.
Sometimes you need a powerful sniffer on your system. Every Mac and every Linux system got it. You just have to use it.
tcpdump
The only thing you have to know, are a few flags.
-i en0 : Listen on this interface.-n : Don’t resolve hostnames.-nn : Don’t resolve hostnames or port names.-X : Show the contents in both hex and ASCII.-XX : Same as -X, but also shows the ethernet header.-v, -vv, -vvv : Increase the amount of packet information you get back.-c : Get n packets and then stop.-S : Print absolute sequence numbers.-e : Get the ethernet header as well.-q : Show less protocol information.-E : Decrypt IPSEC traffic by providing an encryption key.-s : Set the snaplength, i.e. the amount of data that is being captured in bytesExample:
If you just want to see some traffic on the interface:
tcpdump -ni en0
If you want get a lot of information:
tcpdump -i en0 -nnvvvXSs 1514
Of course there are some other options. You can record the traffic into a file, read it from a file. You can also set filters on the command line to get only specific packets.
tcpdump -i en1 -nnvvS tcp and src 10.0.5.1 and dst port 5222