来自 pcap 文件的 grep 字符串

Gil*_*ald 5 grep

我试图找出正确的命令语法。我有一个 pcap 文件,我想使用 grep,而 grep 只是为了从没有文件的情况下取出所有的 uniq ip 地址

所以假设文件名为 capture.pcap 并且在我的主文件夹中,我应该写什么?

我假设正则表达式可以'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}'sort并且也uniq必须包含在内,但似乎 pcap 对 grep 响应不佳,例如,如果我运行,则使用 grep 文件 word 的正常语法不起作用:grep 239 ./capture.pcap我得到重播Binary file ./capture/pcap matches

ste*_*ver 2

尝试添加-a--binary-file=text选项

\n\n

grep -aE \'[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+\' file.pcap
Run Code Online (Sandbox Code Playgroud)\n\n
grep --binary-file=text -E \'[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+\' file.pcap
Run Code Online (Sandbox Code Playgroud)

\n\n


\n这似乎适用于我从 wiki.wireshark.org 下载的随机 pcap 文件,即

\n\n
$ grep -E \'[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+\' NTLM-wenchao.pcap\nBinary file NTLM-wenchao.pcap matches\n
Run Code Online (Sandbox Code Playgroud)\n\n

\n\n
$ grep -aE \'[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+\' NTLM-wenchao.pcap\nHost: 192.168.0.55\nHost: 192.168.0.55\nHost: 192.168.0.55\nLocation: http://192.168.0.55/default.aspx\nMicrosoftSharePointTeamServices: 12.0.0.6421\n<body><h1>Object Moved</h1>This document may be found <a HREF="http://192.168.0."_?"_Ea@y\xc3\x80\xc2\xa8[\xc3\x80\xc2\xa8\xc3\x83P\xc3\xbe\xc2\xb5\xc3\xbb%R\xc3\x91_P\xc3\xbc>\xc3\x95GET /default.aspx HTTP/1.1\nHost: 192.168.0.55\n
Run Code Online (Sandbox Code Playgroud)\n\n

ETC。

\n\n

请注意警告(来自手册页man grep):

\n\n
If TYPE is text, grep processes a binary file as if  it\nwere  text;  this is equivalent to the -a option.  Warning: grep\n--binary-files=text might output binary garbage, which can  have\nnasty  side  effects  if  the  output  is  a terminal and if the\nterminal driver interprets some of it as commands.\n
Run Code Online (Sandbox Code Playgroud)\n\n


\n请注意,虽然您可以使用正则\\d表达式(用于数字),但只有 PCRE 模式下的 grep 支持它(即使用开关-P)。

\n


fal*_*ner 1

grep适用于文本,.pcap 文件是二进制文件,这意味着仅使用 grep无法执行您想要的操作。.pcap 文件格式如果仅使用 grep,您只能在 .pcap 文件中找到那些位于数据包数据部分的 IP。(例如,捕获文件包含网页下载的数据包,其中网页是关于 IP-s 的)因此,简而言之,仅使用 grep无法做到这一点。

但为什么必须只使用 grep 呢?这是某种家庭作业吗?(我三天前回答过一个非常相似的问题。