Question

In python I need to extract the below data from a file called wireshark.txt I made...

In python I need to extract the below data from a file called wireshark.txt I made the element i'm trying to extract Bold in the 1st frame section.

Frame 1, Src:00:14:ee:08:dd:b1, Des:01:00:5e:7f:ff:fa, Type:0x0800
Frame 2, Src:00:14:ee:08:dd:b1, Des:01:00:5e:7f:ff:fa, Type:0x0800
Frame 3, Src:cc:2f:71:3e:ca:a1, Des:14:91:82:36:7a:8d, Type:0x0800
Frame 4, Src:cc:2f:71:3e:ca:a1, Des:14:91:82:36:7a:8d, Type:0x0800

The wireshark.txt file contents:

Frame 1: 372 bytes on wire (2976 bits), 372 bytes captured (2976 bits) on interface 0
Ethernet II, Src: WesternD_08:dd:b1 (00:14:ee:08:dd:b1), Dst: IPv4mcast_7f:ff:fa (01:00:5e:7f:ff:fa)
    Destination: IPv4mcast_7f:ff:fa (01:00:5e:7f:ff:fa)
        Address: IPv4mcast_7f:ff:fa (01:00:5e:7f:ff:fa)
        .... ..0. .... .... .... .... = LG bit: Globally unique address (factory default)
        .... ...1 .... .... .... .... = IG bit: Group address (multicast/broadcast)
    Source: WesternD_08:dd:b1 (00:14:ee:08:dd:b1)
        Address: WesternD_08:dd:b1 (00:14:ee:08:dd:b1)
        .... ..0. .... .... .... .... = LG bit: Globally unique address (factory default)
        .... ...0 .... .... .... .... = IG bit: Individual address (unicast)
    Type: IPv4 (0x0800)
Internet Protocol Version 4, Src: 192.168.1.180, Dst: 239.255.255.250
    0100 .... = Version: 4
    .... 0101 = Header Length: 20 bytes (5)
    Differentiated Services Field: 0x00 (DSCP: CS0, ECN: Not-ECT)
    Total Length: 358
    Identification: 0xfe2a (65066)
    Flags: 0x4000, Don't fragment
    Time to live: 4
    Protocol: UDP (17)
    Header checksum: 0xc505 [validation disabled]
    [Header checksum status: Unverified]
    Source: 192.168.1.180
    Destination: 239.255.255.250
User Datagram Protocol, Src Port: 35064, Dst Port: 1900
Simple Service Discovery Protocol

No.     Time           Source                Destination           Protocol Length Info
      2 0.307821       192.168.1.180         239.255.255.250       SSDP     422    NOTIFY * HTTP/1.1

Frame 2: 422 bytes on wire (3376 bits), 422 bytes captured (3376 bits) on interface 0
Ethernet II, Src: WesternD_08:dd:b1 (00:14:ee:08:dd:b1), Dst: IPv4mcast_7f:ff:fa (01:00:5e:7f:ff:fa)
    Destination: IPv4mcast_7f:ff:fa (01:00:5e:7f:ff:fa)
        Address: IPv4mcast_7f:ff:fa (01:00:5e:7f:ff:fa)
        .... ..0. .... .... .... .... = LG bit: Globally unique address (factory default)
        .... ...1 .... .... .... .... = IG bit: Group address (multicast/broadcast)
    Source: WesternD_08:dd:b1 (00:14:ee:08:dd:b1)
        Address: WesternD_08:dd:b1 (00:14:ee:08:dd:b1)
        .... ..0. .... .... .... .... = LG bit: Globally unique address (factory default)
        .... ...0 .... .... .... .... = IG bit: Individual address (unicast)
    Type: IPv4 (0x0800)
Internet Protocol Version 4, Src: 192.168.1.180, Dst: 239.255.255.250
    0100 .... = Version: 4
    .... 0101 = Header Length: 20 bytes (5)
    Differentiated Services Field: 0x00 (DSCP: CS0, ECN: Not-ECT)
    Total Length: 408
    Identification: 0xfe2d (65069)
    Flags: 0x4000, Don't fragment
    Time to live: 4
    Protocol: UDP (17)
    Header checksum: 0xc4d0 [validation disabled]
    [Header checksum status: Unverified]
    Source: 192.168.1.180
    Destination: 239.255.255.250
User Datagram Protocol, Src Port: 48540, Dst Port: 1900
Simple Service Discovery Protocol

No.     Time           Source                Destination           Protocol Length Info
      3 0.325254       192.168.1.51          146.20.112.65         TCP      55     51333 → 443 [ACK] Seq=1 Ack=1 Win=258 Len=1 [TCP segment of a reassembled PDU]

Frame 3: 55 bytes on wire (440 bits), 55 bytes captured (440 bits) on interface 0
Ethernet II, Src: IntelCor_3e:ca:a1 (cc:2f:71:3e:ca:a1), Dst: BelkinIn_36:7a:8d (14:91:82:36:7a:8d)
    Destination: BelkinIn_36:7a:8d (14:91:82:36:7a:8d)
        Address: BelkinIn_36:7a:8d (14:91:82:36:7a:8d)
        .... ..0. .... .... .... .... = LG bit: Globally unique address (factory default)
        .... ...0 .... .... .... .... = IG bit: Individual address (unicast)
    Source: IntelCor_3e:ca:a1 (cc:2f:71:3e:ca:a1)
        Address: IntelCor_3e:ca:a1 (cc:2f:71:3e:ca:a1)
        .... ..0. .... .... .... .... = LG bit: Globally unique address (factory default)
        .... ...0 .... .... .... .... = IG bit: Individual address (unicast)
    Type: IPv4 (0x0800)
Internet Protocol Version 4, Src: 192.168.1.51, Dst: 146.20.112.65
    0100 .... = Version: 4
    .... 0101 = Header Length: 20 bytes (5)
    Differentiated Services Field: 0x00 (DSCP: CS0, ECN: Not-ECT)
    Total Length: 41
    Identification: 0x69ac (27052)
    Flags: 0x4000, Don't fragment
    Time to live: 128
    Protocol: TCP (6)
    Header checksum: 0xccf1 [validation disabled]
    [Header checksum status: Unverified]
    Source: 192.168.1.51
    Destination: 146.20.112.65
Transmission Control Protocol, Src Port: 51333, Dst Port: 443, Seq: 1, Ack: 1, Len: 1

No.     Time           Source                Destination           Protocol Length Info
      4 0.340841       192.168.1.51          146.20.112.65         TCP      55     51349 → 443 [ACK] Seq=1 Ack=1 Win=255 Len=1 [TCP segment of a reassembled PDU]

0 0
Add a comment Improve this question Transcribed image text
Answer #1
# python 3 script using the wireshark.txt file as provided in the question

import os
from itertools import islice
cwd = "/home/dexter/Desktop"    # working directory
path = cwd + "/wireshark.txt"         # name of the text file
f1 = open(path, "r")            # open text file in read mode
numLines = sum(1 for line in f1)    # counting the number of lines in the text file
f1.close()                      # closing the text file
begin = 0   # read the text file from first row
end = numLines  #read the text file till the last row

finalString=''  # final output string
tempStr=''      #temporary string
temp=''         ##temporary string
count=1         # count variable for Frame number
complete=False  # flag to check if current Frame's information is completely extracted from the text file
                # Src and Destination are mentioned more than once for a particular Frame in text file
                # to avoid copying more than once this flag is needed

with open(path, 'r') as infile:
    lines_gen = islice(infile, begin, end)  # entire text file is sliced into rows

    for line in lines_gen:  # reading line by line

        if (line.find("Frame") != -1):  # if line contains substring "Frame"
            complete=False
            tempStr="Frame"+str(count)+", "
            count+=1

        elif ( (line.find("Src:") != -1)  and (complete==False)):# if line contains substring "Src:" and curent Frame's information is still not completely fetched from text file
            temp=line.split(',')[1]     # extracting just the Src value inside the parenthesis
            temp=temp.partition('(')[2]
            temp=temp.partition(')')[0]
            tempStr=tempStr+"Src:"+temp+", "

        elif ( (line.find("Destination:") != -1)  and (complete==False)):# if line contains substring "Destination:" and curent Frame's information is still not completely fetched from text file
            temp=line.partition('(')[2]     # extracting just the Destination value inside the parenthesis
            temp=temp.partition(')')[0]
            tempStr=tempStr+"Destination:"+temp+", "

        elif ( (line.find("Type:") != -1)  and (complete==False) ):# if line contains substring "Type:" and curent Frame's information is still not completely fetched from text file
            complete=True                   # all information are completely fetched for the current Frame hence making flag 'complete' True
            temp=line.partition('(')[2]     # extracting just the Type value inside the parenthesis
            temp=temp.partition(')')[0]
            tempStr=tempStr+"Type:"+temp+"\n"
            finalString=finalString+tempStr # adding current Frame's complete information into the finalString variable

    print(finalString)





aux2 aux 1.py Рус 1 L. 7: Structure T 1: Project Pycharm Projects untitled python_js te aux2.py Pr.. teht_ml.py të ht_ml1.pyaux2 Q teaux2.py Pycharm Projects untitled python_js te aux2.py Pr.. teht_ml.py te ht_ml1.py te ht_ml2.py aux 1.py complete=F

Add a comment
Know the answer?
Add Answer to:
In python I need to extract the below data from a file called wireshark.txt I made...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Question 13 5 pts Based on the provided Wireshark Capture File and information contained in Frame...

    Question 13 5 pts Based on the provided Wireshark Capture File and information contained in Frame # 12: What is the IPv4 address for the destination of the Layer 3 datagram (based on the particular Layer 3 datagram mentioned in instructions of this quiz)? 10.129.61.67 216.58.216.238 134.124.1.234 107.23.244.231 Question 14 5 pts Based on the provided Wireshark Capture File and information contained in Frame # 12: What is the IPv4 address of the source of the Layer 3 datagram (based...

  • Networks Hi guys. I need some assistance with a few questions below. 1. Which of the...

    Networks Hi guys. I need some assistance with a few questions below. 1. Which of the following is TRUE regarding a TCP 3-way handshake. a.   Consists of 3 segments being sent between 2 hosts       b.   Segments only carry data in the SYN, ACK and sequence number bits and bytes with no data       c.   No ACK is needed for the SYNACK received from the receiver       d.   A, B and C       e.   None of the above 2. Which...

  • What is the network ID in the destination address? What is the host ID in the...

    What is the network ID in the destination address? What is the host ID in the destination address? Write the destination IP address in dotted-decimal notation. Find the source IP address. What class is the source IP address? What is the network ID in the source address? What is the host ID in the source address? Write the source IP address in dotted-decimal notation. Can this message be delivered directly by the source to the destination, or will it require...

  • 1. Can this message be delivered directly by the source to the destination, or will it...

    1. Can this message be delivered directly by the source to the destination, or will it require routers to handle the message? Frame Type Frame Data Destination Hardware Address 6 Bytes Source Hardware Address 6 Bytes 2 Bytes 46 - 1500 Bytes 3 Byte 0 1 2 3 bit 012345678 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 O Version Header Length Type Of Service...

  • Implement the following statements using MS430 assembly instructions. You may use more than one, ...

    Implement the following statements using MS430 assembly instructions. You may use more than one, but you should minimize the number of instructions required. You can use both native and emulated instructions. Use hex notation for all numbers 1. (a) Move the word located in register R14 to R15 (b) Increment the word in R6 by 2. (c) Perform a bitwise ANDing of the word located at address 0x0240 with the datum in R15, placing the results in R15. (d) Rotate...

  • 1. a. In Wireshark, for packet 92, what information in the IP header indicates that the...

    1. a. In Wireshark, for packet 92, what information in the IP header indicates that the datagram has been fragmented? b. What information in the IP header indicates whether this is the first fragment versus a latter fragment? How long is this IP datagram? 2. a. For packet 93, what information in the IP header indicates that this is not the first data fragment? Are there more fragments? If so, how can you tell? - 0 X IP_traceFile File Edit...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT