[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

If I have file containing lines like these: >17:18:44.134482

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 13
Thread images: 1

File: 014.png (202KB, 618x618px) Image search: [Google]
014.png
202KB, 618x618px
If I have file containing lines like these:

>17:18:44.134482 IP 192.168.0.15.37743 > 66.235.141.146.80: Flags [P.], seq 1449:2897, ack 1, win 29200, options [nop,nop,TS val 43002850 ecr 3883480196], length 5
>17:18:44.136984 IP 192.168.0.15.37743 > 66.235.141.146.80: Flags [P.], seq 2897:3114, ack 1, win 29200, options [nop,nop,TS val 43002850 ecr 3883480196], length 5
>17:18:44.151578 IP 192.168.0.15.36011 > 173.194.43.106.443: UDP, length 5
>17:18:44.174462 IP 173.194.43.106.443 > 192.168.0.15.36011: UDP, length 5

How would I go about making a list so that each item within is it's own list containing the 1st IP, 2nd IP, and total length like below?

[['192.168.0.15','66.235.141'.146,10], ['192.168.0.15','173.194.43.106',5], ['173.194.43.106','192.168.0.16',5]]

I think I'm supposed put a loop within a loop, but I can't figure out how to get the IPs and lengths from each line the file. Am I supposed to use a regex or something similar?
>>
>>210209
Sorry, this in in Python.
>>
>>210212
If the thing you're searching for in each string is in the same index every time, you could just split the input by spaces, loop through each line and append [IP#1, IP#2] to a list. Otherwise you can probably use a regex to parse specifically for IPs.
>>
>>210226
I looped the lines with split to make something like

[['a1', 'a2', 'a3'], ['b1', 'b2', 'b3'], ['c1', 'c2', 'c3']]

which places the items I need to be always at index[0], [2], and [-1] but I'm having trouble appending just those indexes to the list while maintaining the list.

I ended up making them one big list like so:

['a1' ,'a2', 'a3', 'b1', 'b2', 'b3', 'c1', 'c2', 'c3']

I'm not exactly sure how to append multiple indexes so that they'd be their own item as below:

[['a1' ,'a2', 'a3'], ['b1', 'b2', 'b3'], ['c1', 'c2', 'c3']]
>>
>>210249
You can make a list of [a1, a2, a3, whatever] each loop and append that list to another list outside the loop.
>>
>>210209
Good lord, man, use AWK.
>>
>>210209
No idea how it would be in python but I made this using javascript, hopefully is what you need
https://plnkr.co/edit/bLQGuCkRrmmdHE5agHxj
>>
>>210312
I used regular expression btw.
>>
>>210212
>Sorry, this in in Python.
Go read up on generators.

You write a generator that picks out the bits from the lines that you're interested in and yields tuples, i.e.

ingests
>17:18:44.134482 IP 192.168.0.15.37743 > 66.235.141.146.80: Flags [P.], seq 1449:2897, ack 1, win 29200, options [nop,nop,TS val 43002850 ecr 3883480196], length 5
and yields
>(192.168.0.15:37743, 66.235.141.146:80, 5)

then you can zip(*) the file into three lists, with the generator in the middle sorting things out.

src,dest,len = zip(*gen_tcpdump('tcpdump.log'))

Here's a good introduction to generators: https://www.oreilly.com/ideas/2-great-benefits-of-python-generators-and-how-they-changed-me-forever
>>
>>210226
>>210282
Thanks for the help. I combined yours with >>210303 to get a list with each sub-list containing with just the indexes I needed.

How would I go about checking if a pair of IPs is already within the list and instead of appending, increment the length.
So with a list of: [['a1','a2', 5], ['b1','b2',5]]
and gets a another list with: ['a1','a2',5]
it'd become: [['a1','a2', 10], ['b1','b2',5]]

>>210312
>>210314
Thanks for helping, it's similar to what I needed (just missing a 3 column for lengths) but in Python.
>>
>>210316
Didn't see the length part, check the code again, just added support to add the lengths too.
https://plnkr.co/edit/bLQGuCkRrmmdHE5agHxj
>>
>>210316
>How would I go about checking if a pair of IPs is already within the list
Concatenate the two IPs into a single string, then use that as the key in a defaultdict.

lengths=defaultdict(int)
for (src, dest, len) in biglonglist:
____lengths[src+dest] += len
>>
>>210321
Actually, I'm being a derp: you can index dictionaries by tuples.


lengths=defaultdict(int)
for (src, dest, len) in biglonglist:
____lengths[(src,dest)] += len
Thread posts: 13
Thread images: 1


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.