Skip to content

Instantly share code, notes, and snippets.

Jay Swan jayswan

Block or report user

Report or block jayswan

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
jayswan /
Created Sep 28, 2016
pipe-able script to check the existence of a GitHub username; returns 200 if found
# Usage: some_command_that_outputs_usernames |
# subject to anonymous API rate limits
xargs -I {} curl -w "%{http_code}\n" -sI -o /dev/null{}
jayswan /
Created Feb 11, 2012
signed 32-bit int to ipv4
def int_to_ip(signed_int):
""" convert a 32-bit signed integer to an IP address"""
# do preventative type checking because I didn't want to check inputs
if type(signed_int) == str or type(signed_int) == int:
signed_int = long(signed_int)
except ValueError:
return "err_ip"
# CUCM occasionally creates CDRs with an IP of '0'. Bug or feature? Beats me.
jayswan /
Created Jul 26, 2016
Scripts to retrieve CIDR blocks for various services
# Fastly
curl -s | jq -r '.addresses | .[]'
# Google
dig @ +short txt | awk '{gsub("ip4:","");for (col=2; col<NF;++col) print $col}'
curl -s | \
jq --raw-output '.prefixes | map(.ip_prefix) | .[]'
jayswan /
Created Jul 10, 2016
Elasticsearch scripted aggregation with joined fields

This script allows you to do SQL GROUPBY-like aggregations on multiple fields in an Elasticsearch index.

Performance will likely be poor on large data sets.

Saved Groovy script in <elasticsearch_dir>/config/scripts/join-param-list.groovy:

return fields.collect { doc[it].value }.join(delimiter);
jayswan /
Created Feb 19, 2016
Convert AWS IP Prefixes to SiLK IP Set
curl -s | \
jq --raw-output '.prefixes | map(.ip_prefix) | .[]' > prefixes.txt
rwsetbuild prefixes.txt aws.ipset
jayswan /
Created Dec 21, 2011
Python Script to find duplicate Cisco interface configs
import os
def print_dup_info(s):
#split config on ! characters
blocks = s.split('!')
stanza_list = []
interface_dict = {}
for block in blocks:
#get rid of blank lines and split each stanza into a list of lines
View gist:c04eee5287cc7cbc5ea1
"query": {
"filtered": {
"filter": {
"bool": {
"must": [
"term": {
"EventID": 4728
View gist:3a7621d909b15c832cfb
In [142]: d
Out[142]: {'TargetUserName.raw': 'Domain Admins'}
In [143]: tt = Search(using=es,index=i)\
View gist:d4ddd71a35bb5f1ad86f
In [144]: tt = Search(using=es,index=i)\
.filter('term',TargetUserName.raw='Domain Admins')\
File "<ipython-input-144-1b746eb83e6f>", line 1
tt = Search(using=es,index=i)\
.filter('term',TargetUserName.raw='Domain Admins')\
SyntaxError: keyword can't be an expression
You can’t perform that action at this time.