Skip to content

Instantly share code, notes, and snippets.

@jeffbryner
jeffbryner / gist:8412843
Last active January 3, 2016 04:59
UTC date from anything
from datetime import datetime
from dateutil.parser import parse
import pytz
def toUTC(suspectedDate,localTimeZone="US/Pacific"):
'''make a UTC date out of almost anything'''
utc=pytz.UTC
objDate=None
if type(suspectedDate)==str:
@jeffbryner
jeffbryner / cmdTimeout.py
Created January 25, 2014 02:15
python code to run an external command with a timeout and return the output
import fcntl
import subprocess
import sys
import shlex
from threading import Timer
import time
import os
'''
python3 code to allow one to run an external command and return the output
'''
@jeffbryner
jeffbryner / gist:8918508
Created February 10, 2014 16:03
dump the veris framework to a item.item.value structure
#!/usr/bin/env python
import json
vDict=json.loads(open('verisc-enum.json').read())
def dict_walker(inCollection, pre=None):
pre = pre[:] if pre else []
#print(pre)
if isinstance(inCollection, dict):
@jeffbryner
jeffbryner / esNodeStatus.py
Created April 12, 2014 22:38
elastic search node status
#!/usr/bin/env python
import json
import requests
r=requests.get(url="http://servername:9200/_nodes/stats?pretty=true")
if r.status_code == 200:
nodestats=r.json()
for node in nodestats['nodes']:
#!/usr/bin/osascript
set inputVolume to input volume of (get volume settings)
if inputVolume = 0 then
set inputVolume to 20
else
set inputVolume to 0
end if
set volume input volume inputVolume
@jeffbryner
jeffbryner / gist:773c31132f6b01645445
Created June 3, 2014 21:46
generate a meteor-style object ID from python for use in mongoDB
def genMeteorID():
return('%024x' % random.randrange(16**24))
def to_unicode_or_bust(obj, encoding='utf-8'):
if isinstance(obj, basestring):
if not isinstance(obj, unicode):
obj = unicode(obj, encoding)
return obj
@jeffbryner
jeffbryner / gist:6229ab504538d34c5717
Created October 9, 2014 23:19
What are my ES thread pools doing
import requests
import json
r=requests.get(url="http://elasticsearchservernamegoeshere:9200/_nodes/stats?pretty=true")
nodestats=r.json()
for node in nodestats['nodes']:
nodename=nodestats['nodes'][node]['name']
threadpool=nodestats['nodes'][node]['thread_pool']
for pool in threadpool:
threads=threadpool[pool]['threads']
rejected=threadpool[pool]['rejected']
@jeffbryner
jeffbryner / gist:00f0abfe64466e700afd
Created November 28, 2014 20:40
Import IOCs into Elastic Search
Input: A json file with iocs of IP address, category and score like:
{
"2.3.4.5" : {
"P2P" : "55"
},
"1.2.3.4" : {
"Brute_Forcer" : "117",
"Scanner" : "117"
}
}
#!/usr/bin/env python
import re
import json
import requests
from datetime import datetime
from dateutil.parser import parse
def apachetime(s):
"""