Skip to content

Instantly share code, notes, and snippets.

@elig0n
Last active May 13, 2022 23:29
Show Gist options
  • Save elig0n/b2a810655c68ee6731df296bec0f32de to your computer and use it in GitHub Desktop.
Save elig0n/b2a810655c68ee6731df296bec0f32de to your computer and use it in GitHub Desktop.
Colorized tcpdump output via awk
#!/usr/bin/awk -f
# tcpdump regular output color wrapper
# usage: tcpdump [options] | awk -f tcpdump.awk
BEGIN {
yellow="\033[33m"
reset="\033[0m"
teal="\033[36m"
lightred="\033[91m"
magenta="\033[35m"
blue="\033[34m"
ORS=""
}
{
for (i=1; i<=NF; i++ ) {
#print i
if (i==1) {
print yellow $1 reset " "
}
else if (i==3) {
print teal $3 reset " "
# parse last dot-field (port/type) with diff. color
}
else if (i==5) {
print lightred $5 reset " "
# parse last dot-field (port/type) with diff. color
}
else if (i==7) {
print magenta $7 reset " "
# parse last dot-field (port/type) with diff. color
}
else if (i==9) {
print blue $9 reset " "
# parse last dot-field (port/type) with diff. color
}
else {
print $i " "
}
}
printf "\n"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment