Write Python Program Using Dkpt Package Read Large Pcap File Dpkt Python Package Q37017911

write a python program using the dkpt package to read a large pcapfile.
dpkt python package


Solution


import dpkt import socket #display the pcap file def print_Pcap (pcap): for (ts1, bufl) in pcap: try: ethl-dpkt.ethernet.Ethe

//sample output

Source: 192.168.43.217 Destination--34.199. 225.157 Source: 192.168.43.217 Destination--34.199. 225.157 Source: 192.168.43.21

//copyable code

#python code

import dpkt

import socket

#display the pcap file

def print_Pcap(pcap):

     for (ts1,buf1) in pcap:

          try:

             eth1 = dpkt.ethernet.Ethernet(buf1)

             ip = eth1.data

             # read source Ip address

             sourcevalue = socket.inet_ntoa(ip.sourcevalue)

             # read destination Ip address

             destinationvalue = socket.inet_ntoa(ip.destinationvalue)

             # Print Ip address

             print ‘Source: ‘ +sourcevalue+ ‘ Destination: ‘+destinationvalue

         except:

                       #pass the value

             pass

#main function

def main():

     # Open file

     file1 =open(‘/home/code/Desktop/test.pcap’)

     #pass

OR
OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.