Skip to content

Instantly share code, notes, and snippets.

View cjamesni's full-sized avatar
💭
I may be slow to respond.

cjamesni

💭
I may be slow to respond.
View GitHub Profile
@cjamesni
cjamesni / python_data_extraction_top_10_ipv4_addrs_via_subprocess.py
Created November 8, 2021 06:28
python_data_extraction_top_10_ipv4_addrs_via_subprocess.py
#!/usr/bin/env python3.9
import subprocess
from subprocess import Popen
command='''
cat /Users/christopher/Desktop/ip_data.log | grep -E -o "(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})" | sort -t . -k 1,1n -k 2,2n -k 3,3n -k 4,4n | uniq -c | sort -rn | head -n 10
'''
process=Popen(command,shell=True,stdout=subprocess.PIPE)
result=process.communicate()
@cjamesni
cjamesni / bash_data_extraction_top_10_ipv4_addrs_egrep_uniq.sh
Created November 8, 2021 06:22
bash_data_extraction_top_10_ipv4_addrs_egrep_uniq.sh
#!/bin/bash
#Extracts top 10 most frequent ipv4 addresses from file
#Where grep options include '-E' to specify an extended regular expression pattern,
#in this case for ipv4, followed by '-o' to print only the matching parts of lines.
#Where sort options include '-t' to denote . as the fields separator / delimiter,
#'-k' to indicate the number of expected key fields to sort from left to right,
#and a further '-rn' option combination to sort results in reverse numerical order.
@cjamesni
cjamesni / async_python_data_extraction_ipv4_addrs_from_sys_dir.py
Last active November 7, 2021 14:38
async_python_data_extraction_ipv4_addrs_from_sys_dir
#!/usr/bin/env python3.9
import asyncio
import re
from pathlib import Path
import aiofiles
directory = '/Users/christopher/Desktop/'
pattern = re.compile(r"(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})")
@cjamesni
cjamesni / get_keychain_pass_subproc.py
Last active September 7, 2021 09:36
Keychain password retrieval function in Python for macOS using standard modules subprocess and getpass.
#!/usr/bin/env python3.9
import subprocess
import getpass
def get_keychain_pass(pw_item_name):
'''Retrieves the password value for a specified keychain item using subprocess.run() and getpass.getuser()'''
return subprocess.run(['security', 'find-generic-password', '-w', '-a', getpass.getuser(), '-s', pw_item_name],
stdout=subprocess.PIPE).stdout.decode('utf-8')