LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 12-22-2016, 02:44 PM   #1
RPN
LQ Newbie
 
Registered: Aug 2005
Distribution: Slackware
Posts: 18

Rep: Reputation: 5
Adding Line Feed Between tcpdump Packets


I am capturing packets to a file with tcpdump and it would really be nice if I could put a line feed or two between each packet for readability. Is there any way you can tell tcpdump to do that? I looked at the man pages and did a Google search but could not find anything. If I missed it in the man pages, my apology.

Last edited by RPN; 12-22-2016 at 02:46 PM.
 
Old 12-22-2016, 03:21 PM   #2
nini09
Senior Member
 
Registered: Apr 2009
Posts: 1,845

Rep: Reputation: 161Reputation: 161
How do you read these captured packet, Wireshark or something else?
 
Old 12-22-2016, 03:22 PM   #3
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,258
Blog Entries: 3

Rep: Reputation: 3713Reputation: 3713Reputation: 3713Reputation: 3713Reputation: 3713Reputation: 3713Reputation: 3713Reputation: 3713Reputation: 3713Reputation: 3713Reputation: 3713
I guess you could pipe the output through sed using a variation on a well-known sed one-liner to double-space a file or stream:

Code:
tcpdump -r your-file.pcap | sed 'G' | less
That works if you want all the lines double-spaced regardless of which packet they are in then G alone would do it.
The G alone would append the hold space to the pattern space, double-spacing the stream.

sed is a very simple and dreadfully concise programming language.

So, if you want to group the packets, then you have to identify the start of the packet with a pattern // and then apply G to it only if the pattern is not present:

Code:
tcpdump -r your-file.pcap | sed '/^..:..:..\./!G' | less
However, packets are two lines so we want to skip that and do the append with every other line. If you're using the default time format for tcpdump then you have colons as the 3rd and 6th character with a period as the 9th character in the lines starting each packet to identify those lines and so the append is skipped for those lines.

Edit: maybe a better, more generic way would be to insert a line ahead of each packet:

Code:
tcpdump -r your-file.pcap | sed '/^..:..:..\./{x;p;x}' | less

Last edited by Turbocapitalist; 12-22-2016 at 03:31 PM.
 
Old 12-22-2016, 03:26 PM   #4
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,553

Rep: Reputation: 7946Reputation: 7946Reputation: 7946Reputation: 7946Reputation: 7946Reputation: 7946Reputation: 7946Reputation: 7946Reputation: 7946Reputation: 7946Reputation: 7946
Quote:
Originally Posted by RPN View Post
I am capturing packets to a file with tcpdump and it would really be nice if I could put a line feed or two between each packet for readability. Is there any way you can tell tcpdump to do that? I looked at the man pages and did a Google search but could not find anything. If I missed it in the man pages, my apology.
Well, there is a reason for the file format. That .pcap format is pretty much a 'standard' for reading in by other programs. But, if you want something non-standard, you could always run it through sed, and shove one in...I don't think there's a way to get tcpdump to do such things by default. That said, have you looked at wireshark instead? It has more options than tcpdump.
 
Old 12-22-2016, 06:29 PM   #5
RPN
LQ Newbie
 
Registered: Aug 2005
Distribution: Slackware
Posts: 18

Original Poster
Rep: Reputation: 5
Nini09: I only need to look at some NTP packets between a time server and a gps receiver/time server over a long period of time looking for some anomalies and tcpdump –A –vvv provides all the information I need.


Turbocapitalist: sed is great idea and I did work something out based on my using tcpdump with the –tttt switch

cat capture.file | sed 's/\(2016-\)/\n\n\1/g' > modified.file

It is not very elegant or as nice as having tcpdump do it, but it works.


TBOne: Thanks for the insight on why there are no linefeeds in the tcpdump output, and I will keep Wireshark in mind for the future.



Thanks to all for taking the time to reply, and I hope you have great holiday season.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
capturing packets with tcpdump BMWE Linux - Networking 5 06-15-2012 04:18 PM
how(what the steps) to feed the Opnet with traffic data gathered using tcpdump tool? linuxFreshMan Linux - Networking 3 01-11-2011 12:14 PM
Scripting question - feed an input file into an if statement line-by-line kmkocot Linux - Newbie 10 01-18-2010 11:49 AM
How to modify tcpdump packets? chinmays Linux - Security 3 09-24-2006 01:31 PM
tcpdump and dropped packets Blindsight Linux - Networking 5 07-14-2003 10:41 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 05:34 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration