Skip to content

Instantly share code, notes, and snippets.

@tomkinsc
Last active January 20, 2016 13:33
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 tomkinsc/c2932097796155f4fd94 to your computer and use it in GitHub Desktop.
Save tomkinsc/c2932097796155f4fd94 to your computer and use it in GitHub Desktop.
This prints the remote IP and local port of SSH reverse tunnels (ssh -R ...) , from the perspective of the machine NOT initiating the tunnel
#!/bin/bash
# From: http://superuser.com/a/804660
sudo lsof -i -n | egrep '\<sshd\>' | grep -v ":ssh" | grep LISTEN | sed 1~2d | awk '{ print $2}' | while read line; do sudo lsof -i -n | egrep $line | sed 3~3d | sed 's/.*->//' | sed 's/:......*(ESTABLISHED)//' | sed 's/.*://' | sed 's/(.*//' | sed 'N;s/\n/:/' 2>&1 ;done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment