average bit rate of packets

average bit rate of packets

Postby bobdx_cool » Sat Mar 29, 2014 11:17 pm

I have a .tcp file with tcp packets, which are in the following format. The size of file is around 60mb.

timestamp, source host, destination host, source TCP port, destination TCP port, and number of data bytes (zero for "pure-ack" packets).

0.418705 2 3 1985 20 0
0.420657 4 5 119 3849 5
0.426512 3 2 20 1985 512
0.427488 3 2 20 1985 512
0.428464 3 2 20 1985 512
0.428465 6 2 1090 2023 0
0.429440 3 2 20 1985 512
0.430416 2 6 2023 1090 512
0.432368 7 8 119 3621 5
0.434320 9 2 4269 6001 64
0.448960 2 9 6001 4269 32
0.448961 10 2 1202 2029 0
0.450912 2 10 2029 1202 512
0.454816 5 4 3849 119 512
0.455793 5 4 3849 119 207
0.461648 11 5 119 3200 5
0.469456 12 2 1064 20 0
0.470432 2 12 20 1064 256
0.474337 13 14 17873 80 0
0.485072 5 11 3200 119 512
0.486048 5 11 3200 119 512
0.486049 5 11 3200 119 121
0.488976 15 2 4472 80 0
0.490928 2 15 80 4472 256
0.491904 2 15 80 4472 256
0.494832 16 5 119 3853 0
0.502640 17 18 2726 25 0
0.504592 19 17 1758 25 512
0.506544 20 17 3173 25 457
0.507520 21 22 1408 80 0
0.510448 22 21 80 1408 512
0.512400 22 21 80 1408 512
0.516305 23 24 3435 80 0
0.524112 23 24 3435 80 227
0.529969 8 7 3621 119 0
0.541680 11 5 119 3200 0
0.542656 25 2 1069 1952 0
0.542657 5 11 3200 119 3
0.542658 9 2 4269 6001 0
0.544608 2 25 1952 1069 512
0.566080 5 26 119 4495 0
0.569984 27 28 1046 25

There are about 1000 pages of such packets.

I need to compute average bit rate of all packets (last column), and also avg bit rate for every 5min window.

I am new to python programming. Please help me on how to proceed.
bobdx_cool
 
Posts: 3
Joined: Sat Mar 29, 2014 11:10 pm

Re: average bit rate of packets

Postby metulburr » Sun Mar 30, 2014 12:04 am

Im not really sure what a tcp file is. So not 100% sure if this would work or not.
Code: Select all
last_indexes = []
with open('packet.tcp') as f:
    lines = f.readlines()
    for line in lines:
        last_as_string = line.split()[-1]
        last_indexes.append(int(last_as_string))
       
avg = sum(last_indexes) / len(last_indexes)
print(avg)
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1420
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: average bit rate of packets

Postby bobdx_cool » Sun Mar 30, 2014 12:28 am

metulburr wrote:Im not really sure what a tcp file is. So not 100% sure if this would work or not.
Code: Select all
last_indexes = []
with open('packet.tcp') as f:
    lines = f.readlines()
    for line in lines:
        last_as_string = line.split()[-1]
        last_indexes.append(int(last_as_string))
       
avg = sum(last_indexes) / len(last_indexes)
print(avg)


Thank you.

Basically I can open a .tcp file with a txt editor.

So, I think I can use the above code to calculate average of all the packsts..

Also, I wanted to know how I can calculate avg bit rate for each 5 minute intervals of all packets in the 1000 pages.
bobdx_cool
 
Posts: 3
Joined: Sat Mar 29, 2014 11:10 pm

Re: average bit rate of packets

Postby metulburr » Sun Mar 30, 2014 12:42 pm

You would essentially do the same, but instead of getting every one, you would do it by muliples of 5 minutes
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1420
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY


Return to Networking

Who is online

Users browsing this forum: No registered users and 2 guests