Как я могу увидеть пакеты при захвате с помощью tcpdump

Как мне увидеть трафик, когда я захватываю его с помощью tcpdump.

Когда я использую -w, он не показывает пакеты во время захвата.

sudo tcpdump -i enp2s0 -w test.pcap
tcpdump: listening on enp2s0, link-type EN10MB (Ethernet), capture size 262144 bytes
^C6 packets captured
7 packets received by filter
0 packets dropped by kernel
]
1
задан 28 March 2019 в 11:55
4 ответа

Итак, после небольшого эксперимента, anwser, если следующее:

sudo tcpdump -i enp2s0 -U -w - | tee test.pcap | tcpdump -r -

-w - : записать в стандартный вывод.

-U : записать пакеты как как только они прибудут. Не ждите, пока буфер заполнится.

Tee выполнит запись в файл, а tcpdump -r - прочитает пакеты из стандартного ввода.

2
ответ дан 3 December 2019 в 16:43

-w вариант - записать вывод tcpdump в файл. вы можете удалить эту опцию, если хотите печатать на своем терминале.

2
ответ дан 3 December 2019 в 16:43

Поскольку вы используете параметр -w, пакеты сохраняются в файл и не отображаются на стандартном выходе. Вот из справочной страницы tcpdumup:

https://www.tcpdump.org/manpages/tcpdump.1.html

-w file
    Write the raw packets to file rather than parsing and printing them out. They can later be printed with the -r option. Standard output is used if file is ``-''. 
    This output will be buffered if written to a file or pipe, so a program reading from the file or pipe may not see packets for an arbitrary amount of time after they are received. Use the -U flag to cause packets to be written as soon as they are received. 
    The MIME type application/vnd.tcpdump.pcap has been registered with IANA for pcap files. The filename extension .pcap appears to be the most commonly used along with .cap and .dmp. Tcpdump itself doesn't check the extension when reading capture files and doesn't add an extension when writing them (it uses magic numbers in the file header instead). However, many operating systems and applications will use the extension if it is present and adding one (e.g. .pcap) is recommended. 
    See pcap-savefile(5) for a description of the file format.  

Если вы хотите делать и то, и другое одновременно, вот способ добиться этого:

Как я могу настроить tcpdump на запись в файл и стандартный вывод соответствующих данных?

2
ответ дан 3 December 2019 в 16:43

Чтобы присоединить новый процесс к текущему дампу, попробуйте:

tail -F -n+0 $dumpfile | tcpdump -r -

2
ответ дан 24 January 2021 в 01:30

Теги

Похожие вопросы