This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def divide_list_into_chunks(input_list, len_of_chunk): | |
""" | |
This function will divide a list into chunks. | |
:param input_list: list to divided | |
:param len_of_chunk: maximum length of each chunk | |
:return: | |
""" | |
for i in range(0, len(input_list), len_of_chunk): | |
yield input_list[i:i + len_of_chunk] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ListManipulations(object): | |
""" | |
This class is used to manipulate various list types. The manipulate types include the deduplication of | |
single and multidimensional lists. Multidimensional lists can also be flattened into a single list. | |
Usage: inputList = list_utilities.ListManipulations(sample_list) | |
print(inputList.deduplicate_multidimensional_list()) | |
""" | |
def __init__(self, input_list): | |
""" | |
:param input_list: list to process |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
class ExpungeCharacters(object): | |
""" | |
This class is used to scrub specific items from text strings. These items include single ASCII characters, | |
non-ASCII characters and single digits. | |
Usage: input_text = '“Projected Set-tled Balan&ce†456$' | |
clean = cleanse_text_utilities.ExpungeCharacters(input_text) | |
print(clean.remove_non_ascii()) | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# use with pyshark | |
import re as regex | |
def extract_conversation_header(packet): | |
""" | |
This function is designed to extract the conversation header information | |
from IPv4 or ICMPv6 packets. | |
:param packet: PCAP packet | |
:return: {protocol} {source_address}:{source_port} --> {destination_address}:{destination_port} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# use with pyshark | |
def extract_ipv6_information(packet): | |
""" | |
This function is designed to extract specific IPv6 elements from a PCAP packet. | |
:param packet: PCAP packet | |
:return: | |
""" | |
try: | |
if 'IPV6' in str(packet.layers): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# use with pyshark | |
def extract_dns_information(packet): | |
""" | |
This function is designed to extract DNS elements from a PCAP packet. | |
:param packet: PCAP packet | |
:return: | |
""" | |
if hasattr(packet, 'udp') and packet[packet.transport_layer].dstport == '53': | |
try: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def extract_http_information(packet): | |
""" | |
This function is designed to extract the HTTP information from IPv4 and ICMPv6 packets. | |
:param packet: PCAP packet | |
:return: | |
""" | |
try: | |
if 'IPv4' in str(packet.layers[0]) and 'HTTP' in str(packet.layers): | |
source_address = packet.ip.src | |
destination_address = packet.ip.dst |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
###################################################################################### | |
# The concurrent.futures module is part of the standard Python library which provides | |
# a high level API for launching asynchronous tasks. | |
###################################################################################### | |
import concurrent.futures | |
###################################################################################### | |
# The Python module Pillow is the folk of PIL, the Python Imaging Library | |
# reference: https://pillow.readthedocs.io/en/3.0.x/index.html | |
###################################################################################### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
###################################################################################### | |
# The concurrent.futures module is part of the standard Python library which provides | |
# a high level API for launching asynchronous tasks. | |
###################################################################################### | |
import concurrent.futures | |
############################################################################################# | |
# The OS module in provides functions for interacting with the operating system. | |
# | |
# os.path() provides various functions to handle pathnames. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
###################################################################################### | |
# The re module is part of the standard Python library which regular expression | |
# matching operations similar to those found in Perl. | |
###################################################################################### | |
import re as regex | |
###################################################################################### | |
# The email module is part of the standard Python library which provides | |
# functions for reading, writing, and sending simple email messages. | |
# |
OlderNewer