클라이언트 (OpenWrt 10.04 라우터의)에 의한 DNS 요청을 tcpdump하고 싶다면
root@ROUTER:/etc# tcpdump -n -i br-lan dst port 53 2>&1
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on br-lan, link-type EN10MB (Ethernet), capture size 96 bytes
22:29:38.989412 IP 192.168.1.200.55919 > 192.168.1.1.53: 5697+ A? foo.org. (25)
22:29:39.538981 IP 192.168.1.200.60071 > 192.168.1.1.53: 17481+ PTR? 150.33.87.208.in-addr.arpa. (44)
^C
2 packets captured
3 packets received by filter
0 packets dropped by kernel
괜찮습니다. 그러나. tcpdumps 출력을 실시간으로 파이프 할 수없는 이유는 무엇입니까?
root@ROUTER:/etc# tcpdump -n -i br-lan dst port 53 2>&1 | awk '/\?/ {print $3}'
^C
root@ROUTER:/etc#
tcpdump 이후에 awk 등을 출력하면 아무 출력도 얻지 못합니다. 왜 그런가요? 파이프 라인을 사용하여 tcpdump의 출력을 실시간으로 처리 할 수없는 이유는 무엇입니까? (따라서 예 : 3 번째 열만 출력하는 예)
이에 대한 해결책이 있습니까?
답변
똑바로 man tcpdump
-l Make stdout line buffered. Useful if you want to see the data while
capturing it. E.g.,
tcpdump -l | tee dat
or
tcpdump -l > dat & tail -f dat
Note that on Windows,``line buffered'' means ``unbuffered'', so that
WinDump will write each character individually if -l is specified.
-U is similar to -l in its behavior, but it will cause output to be
``packet-buffered'', so that the output is written to stdout at the
end of each packet rather than at the end of each line; this is
buffered on all platforms, including Windows.
답변
tcpdump가 패킷을 즉시 쓰도록 옵션 -U
과 함께 사용하십시오 -w
.
답변
tcpdump는 파이프에 쓸 때 출력을 버퍼링하는 것 같습니다. 각 쓰기마다 출력을 플러시하지 않으므로 시스템은 약 4k 바이트 청크로 출력을 씁니다. 필터가 출력을 제한하므로 필터가 충분한 출력을 기록 할 때까지 아무것도 표시되지 않습니다. 그것이 충분히 수집되면 그것은 덩어리로 쓰여지고 몇 줄이 나옵니다.
DNS 조회를 여러 번 트리거하고 그 결과를 확인하십시오.
답변
expect
unbuffer
tty에 쓰고 있다고 가정 하여 명령을 속이는 명령이 있으므로 버퍼링하지 않습니다.
답변
패킷을 사용할 수있는 즉시보아야하는 tcpdump 주위에 실시간 모니터링 래퍼를 만들고 있습니다. 그럼에도 불구하고 -l
약간의 지연이 있습니다.
tcpdump는 이제이 --immediate-mode
문제를 해결했습니다. 작동 시키려면와 함께 사용했습니다 -l
.
이 답변을 참조하십시오 .