SlideShare a Scribd company logo
I need help building a dictionary for the unique packets that this script captures that will then add
them to the created PrettyTable. It needs to also keep track of the number times that the unique
packets occur. The below is the code I have and what the dictionary needs. Thank you for your
help! You will create a dictionary entry for each unique packet observered Unique Packets
combination of SRC-IP, DST-IP, Protocol you will keep track of the count of each unique packet in
the dictionary STRUCT UNPACK FORMATTING NOTES Format C Type Python type Standard
size x pad byte no value c char bytes of length 1 b signed char integer 1 B unsigned char integer 1
? _Bool bool 1 h short integer 2 H unsigned short integer 2 i int integer 4 I unsigned int integer 4 l
long integer 4 L unsigned long integer 4 q long long integer 8 Q unsigned long long integer 8 n
ssize_t integer N size_t integer e (6) float 2 f float float 4 d double float 8 s char[] bytes p char[]
bytes P void* integer ENCODING Character Byte order Size Alignment big-endian standard none !
network (= big-endian) standard none IP Packet ''' import socket import os from prettytable import
PrettyTable # Get the HOST to Sniff From hostname = socket.gethostname() HOST =
socket.gethostbyname(hostname) #HOST = 'localhost' import ipaddress import struct class IP: def
__init__(self, buff=None): header = struct.unpack('> 4 self.ihl = header[0] & 0xF self.tos =
header[1] self.len = header[2] self.id = header[3] self.offset = header[4] self.ttl = header[5]
self.protocol_num = header[6] self.sum = header[7] self.src = header[8] self.dst = header[9] #
human readable IP addresses self.src_address = ipaddress.ip_address(self.src) self.dst_address
= ipaddress.ip_address(self.dst) # map protocol constants to their names self.protocol_map = {1:
"ICMP", 6: "TCP", 17: "UDP"} def main(): socket_protocol = socket.IPPROTO_IP sniffer =
socket.socket(socket.AF_INET, socket.SOCK_RAW, socket_protocol) sniffer.bind((HOST,0))
sniffer.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1) sniffer.ioctl(socket.SIO_RCVALL,
socket.RCVALL_ON) captureDict = {} for i in range(1,10000): packet = sniffer.recvfrom(65565) #
Wait for Packet basePacket = packet[0] # Extract Packet Data from tuple pckHeader =
basePacket[0:20] # Extract the packet header ipOBJ = IP(pckHeader) # Create the IP Object #
Lookup the protocol name try: protocolName = ipOBJ.protocol_map[ipOBJ.protocol_num] except:
protocolName = "Unknown" print("SRC-IP :", ipOBJ.src_address) print("DST-IP :",
ipOBJ.dst_address) print("Protocol:", protocolName) ''' Dictionary code HERE Once you have
processed 10,000 packets update load your results into the prettytable and display. ''' tbl =
PrettyTable(["Occurs", "SRC", "DST", "Protocol"]) print(tbl.get_string(reversesort=True))
sniffer.ioctl(socket.SIO_RCVALL, socket.RCVALL_OFF) if __name__ == '__main__': main()

More Related Content

Similar to I need help building a dictionary for the unique packets tha.pdf

Go Native : Squeeze the juice out of your 64-bit processor using C++
Go Native : Squeeze the juice out of your 64-bit processor using C++Go Native : Squeeze the juice out of your 64-bit processor using C++
Go Native : Squeeze the juice out of your 64-bit processor using C++
Fernando Moreira
 

Similar to I need help building a dictionary for the unique packets tha.pdf (20)

Sphinx autodoc - automated api documentation - PyCon.KR 2015
Sphinx autodoc - automated api documentation - PyCon.KR 2015Sphinx autodoc - automated api documentation - PyCon.KR 2015
Sphinx autodoc - automated api documentation - PyCon.KR 2015
 
MISC TOPICS #2: I18n Data Programming Pearls Random Records Rpx Now Susher St...
MISC TOPICS #2: I18n Data Programming Pearls Random Records Rpx Now Susher St...MISC TOPICS #2: I18n Data Programming Pearls Random Records Rpx Now Susher St...
MISC TOPICS #2: I18n Data Programming Pearls Random Records Rpx Now Susher St...
 
Sphinx autodoc - automated api documentation - PyCon.MY 2015
Sphinx autodoc - automated api documentation - PyCon.MY 2015Sphinx autodoc - automated api documentation - PyCon.MY 2015
Sphinx autodoc - automated api documentation - PyCon.MY 2015
 
Arduino coding class part ii
Arduino coding class part iiArduino coding class part ii
Arduino coding class part ii
 
Quiz 9
Quiz 9Quiz 9
Quiz 9
 
File 10 - CSX 334 _VRA NBO.ppsx
File 10 - CSX 334 _VRA NBO.ppsxFile 10 - CSX 334 _VRA NBO.ppsx
File 10 - CSX 334 _VRA NBO.ppsx
 
Gcrc talk
Gcrc talkGcrc talk
Gcrc talk
 
Basic socket programming
Basic socket programmingBasic socket programming
Basic socket programming
 
Build 2016 - B880 - Top 6 Reasons to Move Your C++ Code to Visual Studio 2015
Build 2016 - B880 - Top 6 Reasons to Move Your C++ Code to Visual Studio 2015Build 2016 - B880 - Top 6 Reasons to Move Your C++ Code to Visual Studio 2015
Build 2016 - B880 - Top 6 Reasons to Move Your C++ Code to Visual Studio 2015
 
Sphinx autodoc - automated API documentation (EuroPython 2015 in Bilbao)
Sphinx autodoc - automated API documentation (EuroPython 2015 in Bilbao)Sphinx autodoc - automated API documentation (EuroPython 2015 in Bilbao)
Sphinx autodoc - automated API documentation (EuroPython 2015 in Bilbao)
 
C Assignment Help
C Assignment HelpC Assignment Help
C Assignment Help
 
The Rust Borrow Checker
The Rust Borrow CheckerThe Rust Borrow Checker
The Rust Borrow Checker
 
Solid C++ by Example
Solid C++ by ExampleSolid C++ by Example
Solid C++ by Example
 
Sergi Álvarez & Roi Martín - Radare2 Preview [RootedCON 2010]
Sergi Álvarez & Roi Martín - Radare2 Preview [RootedCON 2010]Sergi Álvarez & Roi Martín - Radare2 Preview [RootedCON 2010]
Sergi Álvarez & Roi Martín - Radare2 Preview [RootedCON 2010]
 
Querying 1.8 billion reddit comments with python
Querying 1.8 billion reddit comments with pythonQuerying 1.8 billion reddit comments with python
Querying 1.8 billion reddit comments with python
 
Go Native : Squeeze the juice out of your 64-bit processor using C++
Go Native : Squeeze the juice out of your 64-bit processor using C++Go Native : Squeeze the juice out of your 64-bit processor using C++
Go Native : Squeeze the juice out of your 64-bit processor using C++
 
Maker All - Executive Presentation
Maker All - Executive PresentationMaker All - Executive Presentation
Maker All - Executive Presentation
 
Socket programming
Socket programming Socket programming
Socket programming
 
Introduction to pygments
Introduction to pygmentsIntroduction to pygments
Introduction to pygments
 
Secure Programming Practices in C++ (NDC Security 2018)
Secure Programming Practices in C++ (NDC Security 2018)Secure Programming Practices in C++ (NDC Security 2018)
Secure Programming Practices in C++ (NDC Security 2018)
 

More from sukhvir71

I need a Full Runnable code and UML Diagram for the followin.pdf
I need a Full Runnable code and UML Diagram for the followin.pdfI need a Full Runnable code and UML Diagram for the followin.pdf
I need a Full Runnable code and UML Diagram for the followin.pdf
sukhvir71
 
i Local supranational and governmental organisations amp.pdf
i Local supranational and governmental organisations amp.pdfi Local supranational and governmental organisations amp.pdf
i Local supranational and governmental organisations amp.pdf
sukhvir71
 
I need finding assessmentresolutionmon Chief Complaint.pdf
I need  finding assessmentresolutionmon  Chief Complaint.pdfI need  finding assessmentresolutionmon  Chief Complaint.pdf
I need finding assessmentresolutionmon Chief Complaint.pdf
sukhvir71
 

More from sukhvir71 (20)

HW8 Concept Deep Learning Q1 Neural Networrks 2 Points Se.pdf
HW8 Concept Deep Learning Q1 Neural Networrks 2 Points Se.pdfHW8 Concept Deep Learning Q1 Neural Networrks 2 Points Se.pdf
HW8 Concept Deep Learning Q1 Neural Networrks 2 Points Se.pdf
 
httpswwwcancergovnewseventspressreleases2020lung.pdf
httpswwwcancergovnewseventspressreleases2020lung.pdfhttpswwwcancergovnewseventspressreleases2020lung.pdf
httpswwwcancergovnewseventspressreleases2020lung.pdf
 
Human impacts on the environment Prepare a detailed present.pdf
Human impacts on the environment Prepare a detailed present.pdfHuman impacts on the environment Prepare a detailed present.pdf
Human impacts on the environment Prepare a detailed present.pdf
 
HR praclitioners are increasingly performing gender pay audi.pdf
HR praclitioners are increasingly performing gender pay audi.pdfHR praclitioners are increasingly performing gender pay audi.pdf
HR praclitioners are increasingly performing gender pay audi.pdf
 
Humans have contributed to the majority of carbon dioxide C.pdf
Humans have contributed to the majority of carbon dioxide C.pdfHumans have contributed to the majority of carbon dioxide C.pdf
Humans have contributed to the majority of carbon dioxide C.pdf
 
i A content box using the lttextareagt tag which sho.pdf
i A content box using the lttextareagt tag which sho.pdfi A content box using the lttextareagt tag which sho.pdf
i A content box using the lttextareagt tag which sho.pdf
 
HuDs and Autnorties 014 points graded networkx has an imp.pdf
HuDs and Autnorties 014 points graded networkx has an imp.pdfHuDs and Autnorties 014 points graded networkx has an imp.pdf
HuDs and Autnorties 014 points graded networkx has an imp.pdf
 
humans What does the sample suggest about the use of 986F .pdf
humans What does the sample suggest about the use of 986F .pdfhumans What does the sample suggest about the use of 986F .pdf
humans What does the sample suggest about the use of 986F .pdf
 
Hunger Games Catching Fire uso de medios digitales y socia.pdf
Hunger Games Catching Fire uso de medios digitales y socia.pdfHunger Games Catching Fire uso de medios digitales y socia.pdf
Hunger Games Catching Fire uso de medios digitales y socia.pdf
 
I need full assignment with every steps Write a program tha.pdf
I need full assignment  with every steps Write a program tha.pdfI need full assignment  with every steps Write a program tha.pdf
I need full assignment with every steps Write a program tha.pdf
 
I need an explanation for both the wrong and correct answers.pdf
I need an explanation for both the wrong and correct answers.pdfI need an explanation for both the wrong and correct answers.pdf
I need an explanation for both the wrong and correct answers.pdf
 
I need an explanation for the wrong and the correct answer .pdf
I need an explanation for the wrong and the correct answer  .pdfI need an explanation for the wrong and the correct answer  .pdf
I need an explanation for the wrong and the correct answer .pdf
 
I need a help with a project I need to identify Grass lawn.pdf
I need a help with a project I need to identify Grass lawn.pdfI need a help with a project I need to identify Grass lawn.pdf
I need a help with a project I need to identify Grass lawn.pdf
 
I need an excel formula that will return 1 for HE17HE21 and.pdf
I need an excel formula that will return 1 for HE17HE21 and.pdfI need an excel formula that will return 1 for HE17HE21 and.pdf
I need an excel formula that will return 1 for HE17HE21 and.pdf
 
Hxxxp19x21 H5TNii5x21 c Why akould you espect th.pdf
Hxxxp19x21 H5TNii5x21 c Why akould you espect th.pdfHxxxp19x21 H5TNii5x21 c Why akould you espect th.pdf
Hxxxp19x21 H5TNii5x21 c Why akould you espect th.pdf
 
I measured the cooling rate X and surface hardness Y of .pdf
I measured the cooling rate X and surface hardness Y of .pdfI measured the cooling rate X and surface hardness Y of .pdf
I measured the cooling rate X and surface hardness Y of .pdf
 
I need a Full Runnable code and UML Diagram for the followin.pdf
I need a Full Runnable code and UML Diagram for the followin.pdfI need a Full Runnable code and UML Diagram for the followin.pdf
I need a Full Runnable code and UML Diagram for the followin.pdf
 
How would you explain the statement that CPR should not be .pdf
How would you explain the statement that CPR should not be .pdfHow would you explain the statement that CPR should not be .pdf
How would you explain the statement that CPR should not be .pdf
 
i Local supranational and governmental organisations amp.pdf
i Local supranational and governmental organisations amp.pdfi Local supranational and governmental organisations amp.pdf
i Local supranational and governmental organisations amp.pdf
 
I need finding assessmentresolutionmon Chief Complaint.pdf
I need  finding assessmentresolutionmon  Chief Complaint.pdfI need  finding assessmentresolutionmon  Chief Complaint.pdf
I need finding assessmentresolutionmon Chief Complaint.pdf
 

Recently uploaded

Recently uploaded (20)

Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptxJose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
 
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdfDanh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
 
Solid waste management & Types of Basic civil Engineering notes by DJ Sir.pptx
Solid waste management & Types of Basic civil Engineering notes by DJ Sir.pptxSolid waste management & Types of Basic civil Engineering notes by DJ Sir.pptx
Solid waste management & Types of Basic civil Engineering notes by DJ Sir.pptx
 
Benefits and Challenges of Using Open Educational Resources
Benefits and Challenges of Using Open Educational ResourcesBenefits and Challenges of Using Open Educational Resources
Benefits and Challenges of Using Open Educational Resources
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
 
NCERT Solutions Power Sharing Class 10 Notes pdf
NCERT Solutions Power Sharing Class 10 Notes pdfNCERT Solutions Power Sharing Class 10 Notes pdf
NCERT Solutions Power Sharing Class 10 Notes pdf
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdfINU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 

I need help building a dictionary for the unique packets tha.pdf

  • 1. I need help building a dictionary for the unique packets that this script captures that will then add them to the created PrettyTable. It needs to also keep track of the number times that the unique packets occur. The below is the code I have and what the dictionary needs. Thank you for your help! You will create a dictionary entry for each unique packet observered Unique Packets combination of SRC-IP, DST-IP, Protocol you will keep track of the count of each unique packet in the dictionary STRUCT UNPACK FORMATTING NOTES Format C Type Python type Standard size x pad byte no value c char bytes of length 1 b signed char integer 1 B unsigned char integer 1 ? _Bool bool 1 h short integer 2 H unsigned short integer 2 i int integer 4 I unsigned int integer 4 l long integer 4 L unsigned long integer 4 q long long integer 8 Q unsigned long long integer 8 n ssize_t integer N size_t integer e (6) float 2 f float float 4 d double float 8 s char[] bytes p char[] bytes P void* integer ENCODING Character Byte order Size Alignment big-endian standard none ! network (= big-endian) standard none IP Packet ''' import socket import os from prettytable import PrettyTable # Get the HOST to Sniff From hostname = socket.gethostname() HOST = socket.gethostbyname(hostname) #HOST = 'localhost' import ipaddress import struct class IP: def __init__(self, buff=None): header = struct.unpack('> 4 self.ihl = header[0] & 0xF self.tos = header[1] self.len = header[2] self.id = header[3] self.offset = header[4] self.ttl = header[5] self.protocol_num = header[6] self.sum = header[7] self.src = header[8] self.dst = header[9] # human readable IP addresses self.src_address = ipaddress.ip_address(self.src) self.dst_address = ipaddress.ip_address(self.dst) # map protocol constants to their names self.protocol_map = {1: "ICMP", 6: "TCP", 17: "UDP"} def main(): socket_protocol = socket.IPPROTO_IP sniffer = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket_protocol) sniffer.bind((HOST,0)) sniffer.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1) sniffer.ioctl(socket.SIO_RCVALL, socket.RCVALL_ON) captureDict = {} for i in range(1,10000): packet = sniffer.recvfrom(65565) # Wait for Packet basePacket = packet[0] # Extract Packet Data from tuple pckHeader = basePacket[0:20] # Extract the packet header ipOBJ = IP(pckHeader) # Create the IP Object # Lookup the protocol name try: protocolName = ipOBJ.protocol_map[ipOBJ.protocol_num] except: protocolName = "Unknown" print("SRC-IP :", ipOBJ.src_address) print("DST-IP :", ipOBJ.dst_address) print("Protocol:", protocolName) ''' Dictionary code HERE Once you have processed 10,000 packets update load your results into the prettytable and display. ''' tbl = PrettyTable(["Occurs", "SRC", "DST", "Protocol"]) print(tbl.get_string(reversesort=True)) sniffer.ioctl(socket.SIO_RCVALL, socket.RCVALL_OFF) if __name__ == '__main__': main()