Skip to content

Instantly share code, notes, and snippets.


william packetchef

  • 01060
View GitHub Profile
packetchef /
Last active Aug 29, 2015
Encode and decode XOR encryption
# From
def xor_crypt_string(data, key, encode=False, decode=False):
from itertools import izip, cycle
import base64
if decode:
data = base64.decodestring(data)
xored = ''.join(chr(ord(x) ^ ord(y)) for (x,y) in izip(data, cycle(key)))
if encode:
return base64.encodestring(xored).strip()
packetchef / unquoteURLString
Created Jul 6, 2015
Unquote a URL-encoded string
View unquoteURLString
from urllib2 import unquote
# Quoted string seen in POST requests attempting to use PHP file includes
quotedString = (
packetchef /
Created Jul 11, 2015
Pythonic printing of a dictionary and its contents
def prettyDictionary(**kwargs):
for name, value in kwargs.items():
print('{name} :: {value}'.format(name=name, value=value))
import urllib2
import simplejson as json
url = ''
ipinfo = urllib2.urlopen(url).read()
jipinfo = json.loads(ipinfo)
packetchef /
Last active Aug 29, 2015
Demonstrate handling of command line options using optparse
import optparse
import sys
global debug
progDesc = (
'Welcome to %prog. It\'s meant for frobbing foozles, and otherwise'
'making for better frognosticators.'
packetchef / splunk_synch_search
Created Jul 13, 2015
Example of synchronous search in Splunk with default output in JSON
View splunk_synch_search
packetchef / splunk_asynch_search
Created Jul 13, 2015
Example of asynchronous search in Splunk with loop to check job status and default output in JSON.
View splunk_asynch_search
packetchef /
Created Jul 19, 2015
Define a class that accepts a variable number of arguments at instantiation time and sets them as attributes
class myVariableClass:
def __init__(self, name, **kwargs): = name
self.classType = 'Variable class'
for key, value in kwargs.items():
setattr(self, key, value)
from pprint import pprint
myVar = myVariableClass('test class', string1='abc', int1=999, string2='end this')
packetchef /
Created Jul 21, 2015
Demonstrate rot13 encoding
import string
rot13 = string.maketrans(
encodedString = string.translate('Hypatia', rot13)
decodedString = string.translate(encodedString, rot13)
print('Encoded string is {string}'.format(string=encodedString))
packetchef /
Created Aug 4, 2015
Generate a block of text based on a salt and static string - do not consider to be random
# Future print lets us easily remove trailing newlines
from __future__ import print_function
import hashlib
salt = "N"
while i < 5000:
print(hashlib.md5('thisismystring' + (salt * i)).hexdigest(), end='')
i += 1
packetchef / get_interface_data
Created Aug 6, 2015
For OS X: show details for all network interfaces
View get_interface_data
NETWORKSETUP=$(whereis networksetup)
NETWORKSERVICES=$($NETWORKSETUP -listallnetworkservices | grep -v '^An asterisk')
for service in $NETWORKSERVICES
echo "Service config for $service"
$NETWORKSETUP -getinfo "$service"