Skip to content

Instantly share code, notes, and snippets.

@dotwaffle
Created April 10, 2015 11:07
Show Gist options
  • Save dotwaffle/bdeaec323f0815958eff to your computer and use it in GitHub Desktop.
Save dotwaffle/bdeaec323f0815958eff to your computer and use it in GitHub Desktop.
List all the TCP connections on a box, and get the TCP_INFO for analysis
#!/bin/bash
ss -tine \
| tr '\t' ' ' \
| sed \
-e ': # first line is for humans' \
-e '1d' \
-e ': # remove the skbuf stuff' \
-e 's/sk:ffff[0-9a-fA-F]\+//g' \
-e ': # remove the ino stuff' \
-e 's/\s\+ino:[0-9]\+//g' \
-e ': # join the next two lines together' \
-e 'N;s/\n/ /g' \
-e ': # move the timer to the end (neater)' \
-re 's/(timer:[^ ]+)(.*)/\2 \1/g' \
-e ': # move the uid to the end (neater)' \
-e 's/(uid:[0-9]+)(.*)/\2 \1/g' \
-e ': # remove all space after the IP/ports' \
-e 's/\s+cubic/\tcubic/g' \
-e ': # send does not have a colon, annoying!' \
-e 's/send /send:/g' \
-e ': # remove the annoying <->' \
-e 's/<->//g' \
| sort -rnk3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment