Skip to content

Instantly share code, notes, and snippets.

@jlongman
jlongman / pssh.sh
Created May 25, 2015 14:30
ping test a host
function pssh() {
host=$1
shift
ping -o $host && growl "$host connected" && ssh $host $@
}
@jlongman
jlongman / rshark.sh
Last active August 29, 2015 14:20
Remote ssh or netcat to wireshark
HOST=$1
ssh root@$HOST tcpdump -U -s0 -w - 'not port 22' | wireshark -k -i -
# or nc -l 12345 # and
# tcpdump -l -ni em0 -s0 -w - | nc $ORIGINAL_HOST 12345
@jlongman
jlongman / netgraph_tee_splice.sh
Created May 11, 2015 21:45
Netgraph node splicing - add a Tee node
#!/bin/sh
# builds an ng_tee with an ng_iface tied in where the LEFT and LEFT_HOOK were so tcpdump can observe
LEFT=$1
LEFT_HOOK=$2
### ngctl show $LEFT:$LEFT_HOOK
# take RIGHT, RIGHT_HOOK from above line
RIGHT=`ngctl show $LEFT:$LEFT_HOOK | grep -Eo 'ID: [0-9a-e]+' | grep -Eo '[0-9a-e]+'`
RIGHT_HOOK=`ngctl show $LEFT:$LEFT_HOOK | grep $LEFT_HOOK | awk '{print $1}'`
ngctl rmhook $LEFT: $LEFT_HOOK
ngctl mkpeer $LEFT: tee $LEFT_HOOK left
@jlongman
jlongman / http11get.sh
Last active August 29, 2015 14:20
http/1.1 client one liner
export USER_AGENT="Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:27.0) Gecko/20100101 Firefox/27.0"
http10get() {
python -c "import urllib; urllib.urlretrieve(\"$1\")"
}
http11get () { python2.7 -c "from urlparse import urlparse
import os
import urllib2
path = \"$XIPIX_DIR\" + urlparse(\"$1\").path;
try:
@jlongman
jlongman / ipfw_lite.sh
Created May 11, 2015 21:41
ipfw show highlighting
#!/bin/sh
# requires line_lite.sh: https://brianin3d.wordpress.com/2008/05/14/scripting-with-ansi-color-codes/
ipfw show | ./line_lite.sh '\*\*\*' green:underline | ./line_lite.sh 'tag.*123' bright
# WIDE - 2 columns - must add pr from a freebsd host
ipfw show | ./line_lite.sh '\*\*\*' green:underline | ./pr -2 -t -w 300 -
ipfw show | ./line_lite.sh '\*\*\*' green:underline | ./line_lite.sh "stat:" bright | ./pr -2 -t -w 300 -
# live update
while 1
ipfw show | ./line_lite.sh '\*\*\*' green:underline | ./line_lite.sh "stat:" bright | ./pr -2 -t -l 86 -w 272 - > /tmp/foo
clear
@jlongman
jlongman / unwrap-gre.py
Created May 11, 2015 21:40
dpkt GRE stripping
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Extracts IP content from GRE and writes to arg[1].out
# Drops non GRE
# requires dpkt gre patch
import dpkt
import sys
fin = open(sys.argv[1])
fout = open(sys.argv[1] + ".out", "w")
pcap = dpkt.pcap.Reader(fin)
@jlongman
jlongman / pixel_diff.py
Created May 11, 2015 21:33
A numeric diff of two images
#!/bin/python2.7
from itertools import izip
from PIL import Image
import argparse
import os
parser = argparse.ArgumentParser()
#parser.add_argument("--preserve_case", "-p", action = 'store_true')
# parser.add_argument("--file-list", "-f", action = 'store_true')
parser.add_argument("files", nargs = 2, type = str, default = None)
@jlongman
jlongman / set_pipe.sh
Last active August 29, 2015 14:20
FreeBSD pipe satsim
#!/bin/sh
# simple one, assumes pipe
# usage: set_pipe bw delay [errorpercentage]
#ipfw pipe 1 config bw $1Kbits delay $(($2/2))ms plr $3 queue $((($1*$2)/8))bytes
#
# advanced, sets pipe
if [ $# "<" 6 ] ; then
echo "usage: $0 <Client IP> <Server IP> <fw bw, kbps> <return bw, kbps> <delay, ms> <ber, float>";
fi
ipfw -f flush
@jlongman
jlongman / bridge.sh
Created May 11, 2015 21:24
FreeBSD bridge
#!/bin/sh
ifconfig bridge0 > /dev/null
if [ $? != 0 ] ; then
ifconfig bridge create
fi
if1=em0
if2=em3
ifconfig bridge0 addm $if1 addm $if2 up
ifconfig $if1 up
ifconfig $if2 up
@jlongman
jlongman / vbserial.sh
Created May 11, 2015 21:23
VirtualBox and socat
boxsocket=$1
#boxpty=$2
# host pipe
socat UNIX-CONNECT:$boxsocket TCP-LISTEN:8040 &
telnet localhost 8040
# host socket
socat UNIX-CONNECT:/tmp/$boxsocket PTY,link=$boxpty &
screen $boxpty