Skip to content

Instantly share code, notes, and snippets.

View mjseeley's full-sized avatar

Mike Seeley mjseeley

  • Mt. Sterling, Illinois
View GitHub Profile
import pip
from subprocess import call
for dist in pip.get_installed_distributions():
call("pip install --upgrade " + dist.project_name, shell=True)
@mjseeley
mjseeley / dlAttachments.py
Last active October 17, 2020 12:32 — forked from baali/dlAttachments.py
Forked to add downloading of files with the same name and different contents. | WARNING: [messy code]
# Download ALL attachments from GMail
# 1. Script needs to be run via console not in an IDE, getpass.getpass() will fail otherwise.
# https://docs.python.org/2/library/getpass.html
# 2. Make sure you have IMAP enabled in your GMail settings.
# https://support.google.com/mail/troubleshooter/1668960?hl=en
# 3. If you are using 2 step verification you may need an APP Password.
# https://support.google.com/accounts/answer/185833
# 4. Reference information for GMail IMAP extension can be found here.
# https://developers.google.com/gmail/imap_extensions
@mjseeley
mjseeley / print_class.py
Last active December 1, 2019 15:24
Print class elements all pretty like
print '\n'.join("%s: %s" % item for item in vars(x).items()) # replace 'x'.
@mjseeley
mjseeley / dpkt_pcap_example.py
Created November 6, 2014 21:07
Simple dpkt example for processing (tcpdump)pcap files
import dpkt
import socket
# Function/arguments: get_rdns(ip)
# Description: Perform a reverse DNS query for the passed-in IP address.
# Returns: String: the reverse DNS name, or ''.
def get_rdns(ip):
try:
result = socket.gethostbyaddr(ip)[0]
@mjseeley
mjseeley / hexmactodecmac.py
Last active August 29, 2015 14:08
Convert hex MAC address to decimal MAC address (00AABBCCDDEE -> 123.123.123.123.123.123)
# Function/arguments: hexmactodecmac(hexmac)
# Description: Convert hex MAC address to decimal MAC address (00AABBCCDDEE -> 123.123.123.123.123.123)
# Returns: MAC address in dec format with delimiters(".")
def hexmactodecmac(hexmac):
hexmac = re.findall(r'.{1,2}', hexmac, re.DOTALL)
decmac = '.'.join(str(int(i, 16)).zfill(1) for i in hexmac)
return decmac
@mjseeley
mjseeley / decmactohexmac.py
Last active August 29, 2015 14:08
Convert Decimal MAC address to hex MAC address (123.123.123.123.123.123 -> 00AABBCCDDEE)
# Function/arguments: decmactohexmac(decmac)
# Description: Convert Decimal MAC address to hex MAC address (123.123.123.123.123.123 -> 00AABBCCDDEE)
# Returns: MAC address in hex format without delimiters
def decmactohexmac(decmac): #
decmac = decmac.split(".")
hexmac = ''.join(str(hex(int(i)).lstrip('0x')).zfill(2) for i in decmac).upper()
return hexmac
@mjseeley
mjseeley / now.py
Created November 6, 2014 20:47
Get current date - time and format it.
import time
# Function/arguments: now()
# Description: Returns the current system time for the logfile.
# Returns: A string with the current time for the logfile.
def now():
result = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
return result
@mjseeley
mjseeley / get_rdns.py
Created November 6, 2014 20:43
def get_rdns(ip)
import socket
# Function/arguments: get_rdns(ip)
# Description: Perform a reverse DNS query for the passed-in IP address.
# Returns: String: the reverse DNS name, or ''.
def get_rdns(ip):
try:
result = socket.gethostbyaddr(ip)[0]
except socket.herror:
# print 'Unable to get rDNS for', ip