Skip to content

Instantly share code, notes, and snippets.

@postwait
Created March 21, 2013 03:17
Show Gist options
  • Select an option

  • Save postwait/5210439 to your computer and use it in GitHub Desktop.

Select an option

Save postwait/5210439 to your computer and use it in GitHub Desktop.
#!/usr/bin/bash
PORT=$1
[[ -z "$PORT" ]] && PORT=80
/opt/omni/sbin/tcpdump -nnn -ttq -s 384 'tcp port '$PORT' and ((((ip[2:2] - ((ip[0]&0xf)*4)) - ((tcp[12]&0xf0)/4)) != 0 and src port '$PORT') or ((tcp[tcpflags] & (tcp-syn|tcp-ack)) == tcp-syn))' | \
PORT=$PORT /usr/bin/gawk '
BEGIN { DPORT=sprintf(".%d", ENVIRON["PORT"]) }
{
gsub(".[0-9]+(: | >)"," & ");
gsub("[:=]"," ");
EP=sprintf("%s%s", ($4==DPORT)?$6:$3, ($4==DPORT)?$7:$4);
if(S[EP] == "C" && $4 == DPORT) { printf("%f %s\n", ($1 - L[EP])*2, EP) > "/dev/stderr"; }
S[EP]= ($4==DPORT)?"S":"C";
L[EP]= $1;
}
'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment