Skip to content

Instantly share code, notes, and snippets.

@floreo
Created July 6, 2017 21:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save floreo/c2a25858881b2080b9ecf668e9f1ce82 to your computer and use it in GitHub Desktop.
Save floreo/c2a25858881b2080b9ecf668e9f1ce82 to your computer and use it in GitHub Desktop.
Funny script to make a graph of the current connections
#!/usr/bin/env bash
# requires graphviz
dot -Tpng -o network-$(date +%Y-%m-%d-%H-%M-%S).png < <(sudo netstat -ntu | awk 'BEGIN \
{
print "digraph network {\n\tsize=\"35\" node [shape = circle, style=filled];\n\tratio = fill;\n\trankdir=LR;"; \
} \
/^(ud|tc)p.+/ \
{
match($4, /(.+):([0-9]{1,5})$/, _loc);
match($5, /(.+):([0-9]{1,5})$/, _dist);
switch($6) \
{ \
case "ESTABLISHED":
_fontcolor="green"
break;
case "CLOSE_WAIT":
_fontcolor="orange"
break;
case "TIME_WAIT":
_fontcolor="red"
break;
case "LAST_ACK":
_fontcolor="purple"
break;
default:
_fontcolor="blue"
break;
} \
print "\t\""_loc[1]"\" -> \""_dist[1]"\" [ label = \""_loc[2]" <-> "_dist[2]"\" fontcolor="_fontcolor" ];" \
} \
END \
{
print "}"; \
}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment