Write tcpdump output in a text file into a single line

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-05 04:09:09

问题


I want to concatenate all lines in text output into one line. With the following command I can monitor DHCP traffic:

tcpdump -lni eth0 -vvv -s 1500 '((udp port 67) and (udp[247:4] = 0x63350103))' | grep --line-buffered -E -i 'client-id|requested-ip|hostname'

For every new connection I see 3 results ( IP, MAC, Hostname ) every one of them on a new line.

That's possible to write this three every results but into only one line and write on a file?


回答1:


Use tr to remove newlines with -d. Running on my machine and using en0 instead of eth0, I see this on one line:

$ tcpdump -lni en0 -vvv -s 1500 '((udp port 67) and (udp[247:4] = 0x63350103))' | grep --line-buffered -E -i 'client-id|requested-ip|hostname' | tr -d '\n' > output.txt
$ cat output.txt
        Client-ID Option 61, length 7: ether 6c:96:cf:d8:7f:e7      Requested-IP Option 50, length 4: 172.31.99.198     Hostname Option 12, length 3: "mbp"

> Will overwrite a file with contents of stdin.
Check out tr's manpage.



来源:https://stackoverflow.com/questions/59224563/write-tcpdump-output-in-a-text-file-into-a-single-line

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!