Skip to content

Instantly share code, notes, and snippets.

@kuzuha
Created August 29, 2012 23:33
Show Gist options
  • Save kuzuha/3520393 to your computer and use it in GitHub Desktop.
Save kuzuha/3520393 to your computer and use it in GitHub Desktop.
tcpdump filter
#!/usr/bin/env perl
$buf = '';
while(<STDIN>) {
$flag = $_ =~ m/^\s+0x[\da-f]{4}: /;
if (!$flag) {
$buf =~ s/\s//g;
$buf =~ s/[0-9A-Fa-f][0-9A-Fa-f]/pack("C", hex $&)/eg;
$buf = substr($buf, 52);
$buf =~ s/[\x00-\x08\x0b-\x0c\x0e-\x1f\x7f-\xff]/ /g;
print "$buf\n\n";
$buf = '';
print $_;
} else {
$_ =~ s/^[^:]+: //gm;
$buf .= $_;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment