Extracting strings
Hello friends,
I captured and saved to a file in plain txt from wireshark, i am trying to use awk or any command to extract the time, source ip address and destination address, i tried using grep it gives me all the line containg ip address, pls can anybody help me on this this is how the information looks when you open the file: No. Time Source Destination Protocol Info 1617 14.30 10.49.48.95 64.191.203.30 HTTP POST /login HTTP/1.1 (application/x-www-form-urlencoded) tt1ect |
This looks like a simple task for AWK. Assuming that the format is always the same, you simply have to extract by field, using " " (space) as the delimiter.
Example---this print the 2nd, 3rd and 4th field, with tabs: awk '{print $2"\t"$3"\t"$4}' filename Really good AWK tutorial (and much more) here: http://www.grymoire.com/Unix/Awk.html |
Moin,
you don't need grep in this case. A simple way to get the fields 2 - 4 is cut: Code:
jan@jack:~/tmp> echo '1617 14.30 10.49.48.95 64.191.203.30 HTTP POST /login HTTP/1.1 (application/x-www-form-urlencoded)' | cut -f2-4 -d' ' Code:
jan@jack:~/tmp> echo '1617 14.30 10.49.48.95 64.191.203.30 HTTP POST /login HTTP/1.1 (application/x-www-form-urlencoded)' | awk ' { print $2, $3, $4 } ' Code:
jan@jack:~/tmp> echo '1617 14.30 10.49.48.95 64.191.203.30 HTTP POST /login HTTP/1.1 (application/x-www-form-urlencoded)' | sed 's/^[0-9]* \([^ ]*\) \([^ ]*\) \([^ ]*\) .*/\1 \2 \3/' Jan |
Please don't post the same thing twice----(perhaps it was an error)
I'll ask that the two be merged since both have replies |
Moin,
Quote:
Jan |
To be honest, I'd just save the data from Wireshark/tcpdump as a binary file and then write a C(++) program using libpcap to get the info you want.
|
Quote:
|
Quote:
|
Quote:
OP posted this twice and each one had responses, so the threads were merged. |
When I was doing my MSc project, I had to analyse tcpdump data and initially tried string parsing. It was very messy, so I just went and learned to use libpcap. Makes life easier!
As requested, here's a C++ program making use of libpcap to get source and destination addresses and ports and timestamps: Code:
#include <pcap.h> |
Thanks for the -lpcap example.
|
All times are GMT -5. The time now is 10:06 PM. |