Skip to content

Instantly share code, notes, and snippets.

@johnbumgarner
johnbumgarner / chunk_list.py
Last active December 1, 2020 15:54
This Python function is used to divide a list into individual chucks based on a maximum length variable.
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]
@johnbumgarner
johnbumgarner / list_utilities.py
Last active December 1, 2020 16:09
This Python Class is designed to manipulate various list types (e.g., multidimensional list)
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
@johnbumgarner
johnbumgarner / cleanse_text_utilities.py
Created December 1, 2020 16:09
This Python Class is designed to scrub specific items from text strings.
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())
"""
@johnbumgarner
johnbumgarner / extract_conversation_header.py
Last active December 2, 2020 16:25
This function is designed to extract the conversation header information from IPv4 or ICMPv6 packets.
# 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}
@johnbumgarner
johnbumgarner / extract_ipv6_information.py
Created December 2, 2020 16:18
This function is designed to extract specific IPv6 elements from a PCAP packet.
# 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):
@johnbumgarner
johnbumgarner / extract_dns_information.py
Created December 2, 2020 16:21
This function is designed to extract DNS elements from a PCAP packet.
# 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:
@johnbumgarner
johnbumgarner / extract_http_information.py
Created December 2, 2020 16:24
This function is designed to extract the HTTP information from IPv4 and ICMPv6 packets.
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
@johnbumgarner
johnbumgarner / comparison_scores_ahash.py
Last active August 25, 2022 04:41
This function is designed to generate comparison scores between two image using aHash from ImageHash.
######################################################################################
# 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
######################################################################################
@johnbumgarner
johnbumgarner / comparison_scores_skimage.py
Last active January 2, 2021 13:20
This function is designed to generate comparison scores between two image using ssim from skimage.
######################################################################################
# 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.
@johnbumgarner
johnbumgarner / parse_email_message.py
Created January 2, 2021 17:02
This function is designed to parse an email message using the built-in Python module email.
######################################################################################
# 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.
#