Extracting and Coverting values from a K12 Textfile (Wireshark capture)

 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions Extracting and Coverting values from a K12 Textfile (Wireshark capture)
# 1  
Old 10-29-2009
Extracting and Coverting values from a K12 Textfile (Wireshark capture)

1. The problem statement, all variables and given/known data:

Using the Windows version of Wireshark, record at least 100 entries of normal network traffic (in a file). Pick 2 packets and analyze the contents showing the header and data information (ie what port #, service etc). You can use the Wireshark display as a confirmation by loading the file back into Wireshark. Examine the format of the Wireshark file and write a short Perl script to extract the source and destination IP address and the protocol type from each entry in the file and print it on the screen.

Now my understanding of the problem given to me for lab homework is that you write a script (Perl preferred) that can read a wireshark capture file and sort though the packet's data to grab what you want, except it should be able to work on any # of packets.

2. Relevant commands, code, scripts, algorithms:

As far as I know with this type of script I've asked several classmates and everyone is doing them differently, some are using arrays (1-4 at most) and some are using strings that break down into substrings. I've heard of the pack/unpack and hex/oct perl commands and heard that you can probably pull this off with awk/gawk

3. The attempts at a solution (include all code and scripts):

My first attempt with this was using Perl with an array but it did not work too well as I got stuck, I also tried to do it with substrings but couldn't figure that out (past courses for scripting taught 0 things about scripting but rather programming in Perl/Bash).
I will post the code for my 1st program, as for the 2nd one using strings I believe I deleted it.
Code:
#!/usr/bin/perl
open (INFILE, "samplecapture.txt" | die "$!\n";
$n = 0;
$c = 0;
while (<INFILE>)
{
if (index($_,"|") == 0)
{
@data[$n] = $_;
$n++;
}
}
print @data; #this is just to check if the array is filled or not
close (INFILE);
foreach $data(@data)
{
@clean[$c] = split(/\|/,$data);
$c++;
}
print @clean;

As far as I know the foreach statement does not work as my clean array has nothing in it and I might've messed that up.

My second attempt was using a bash script with the awk command
I could grab what I wanted from the file but I have no idea how to manipulate it to do what I want such as coverting the hex values of the source and destination IP to decimal.
This is the code I was using but I gave up after doing some research on awk:
Code:
#!/bin/usr/sh
awk '{FS="|"}{print "Protocol",$26,"Source IP",$29,$30,$31,$32,"Destination IP",$33,$34,$35,$36}' samplecapture.txt

Those are pretty much the locations of the data I want to extract after trial & error and also looking at each packet through wireshark.

Sample of the K12 Textfile
Code:
+---------+---------------+----------+
21:01:34,599,128   ETHER
|0   |00|1e|58|28|7a|ef|00|1c|7e|72|75|ae|08|00|45|00|00|30|4c|4d|40|00|80|06|6e|ad|c0|a8|00|81|0a|8c|74|18|1b|36|00|50|13|73|ff|b9|00|00|00|00|70|02|ff|ff|14|9f|00|00|02|04|05|b4|01|01|04|02|

+---------+---------------+----------+
21:01:36,328,508   ETHER
|0   |01|00|5e|00|00|01|00|1e|58|28|7a|ef|08|00|45|00|00|1c|00|00|00|00|01|02|19|36|c0|a8|00|01|e0|00|00|01|11|64|ee|9b|00|00|00|00|00|00|00|00|00|00|00|00|00|00|00|00|00|00|00|00|00|00|

4. School (University) and Course Number:
SAIT Southern Alberta Institute of Technology, ITSC 311
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Taking key values from one file and extracting values from another file

Hi, I have two files with values in both. File1: cat 2 3 dog 4 5 elephant 6 7 camel 2 3 File2: ----+--gkf;ajf= ---+---- +----- cat -------=----+ 3 | 4 ----- dog ------++-- 5 | 9 ----++-- elephant | 5 | 7 ---++ camel ------ ++++_---- || 8 | 9 I want the final file as: cat 4... (1 Reply)
Discussion started by: npatwardhan
1 Replies

2. Shell Programming and Scripting

How to separate sorte different characters from one textfile and copy them in a new textfile?

My first post, so don't kill me :) Say i open some textfile with some example like this. on the table are handy, bread and wine Now i know exactly what is in and i want to separate and sorted it in terminal to an existing file with another 2 existing lines in like this: table plane ... (3 Replies)
Discussion started by: schwatter
3 Replies

3. Shell Programming and Scripting

Extracting fetching values

I have a file like this ############################################ # ParentFolder Flag SubFolders Colateral 1 Source1/Checksum CVA 1 Source1/Checksum Test 1 VaR/Checksum Test2 1 SVaR/Checksum FX 1 ... (6 Replies)
Discussion started by: manas_ranjan
6 Replies

4. Shell Programming and Scripting

Capture query returned values in file.

Hi All, I am connecting to Oracle DB from UNIX script. Want to capture all dates between start date and end date and store them in file. Once this is done, want to read dates one by one. How to achive this in UNIX and Oracle? Please let me know if you have any idea on the same. Thanks and... (4 Replies)
Discussion started by: Nagaraja Akkiva
4 Replies

5. Shell Programming and Scripting

How to capture C program return values in Kshell

I have a K shell script (ksh) that needs to return an email address. A C program was written (prog1) to now access the email address off of an oracle table. The call to the program in the ksh is prog1 -p parm1 Based on Parm1 the program will read an oracle table and retrieve the email... (2 Replies)
Discussion started by: jclanc8
2 Replies

6. Shell Programming and Scripting

how to capture oracle function returning 2 values in unix

i have an oracle function which returns two values, one is the error message if the function encounters anything and another one which returns a number i need to capture both and pass it on to unix shell script how to do it (2 Replies)
Discussion started by: trichyselva
2 Replies

7. Shell Programming and Scripting

Capture values using multiple regex patterns

I have to read the file, in each line of file i need to get 2 values using more than one search pattern. ex: <0112 02:12:20 def > /some string/some string||some string||124 i donot have same delimiter in the line, I have to read '0112 02:12:20' which is timestamp, and last field '124' which is... (4 Replies)
Discussion started by: adars1
4 Replies

8. UNIX for Advanced & Expert Users

Capture child processes and change return values question

Thanks in advance. My environment is Ubuntu 9.04 desktop customized to be a high school classroom server for teaching code development. I have a unique "fake" jail called "lshell" which is very easy to setup and restricts users to commands that I dictate DISALLOWING ANYTHING ELSE. These... (6 Replies)
Discussion started by: tuxhats
6 Replies

9. Shell Programming and Scripting

Read textfile and enter the values in array

Hi, I want to put values in .txt file into array. Example : $vi repo.txt abc def ghi jkl mno pqr i want the output to be like this: $echo ${mydf} abc $echo ${mydf} def $echo ${mydf} ghi (3 Replies)
Discussion started by: luna_soleil
3 Replies

10. Shell Programming and Scripting

Extracting values from files

Im trying to create a utility that can do unit conversions using a seperate formula file(one which i can add conversions to at a later date). however i'm stuck when it comes to pulling the formulas out of the formula file for use in the script. heres a rundown of what the script does. The... (4 Replies)
Discussion started by: Master Error
4 Replies
Login or Register to Ask a Question