Last active
August 29, 2015 13:56
-
-
Save harunyardimci/8955138 to your computer and use it in GitHub Desktop.
find connected hostnames from netstat output
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| netstat -tuna | awk '$5 ~ /^[0-9]/ { print $5 }' | sed -e '/:[0-9]*/s/:[0-9]*//' | sort | uniq -c | sort -rn | while read line; do COUNT=$(echo $line | awk '{ print $1 }'); IP=$(echo $line | awk '{ print $2 }'); HNAME=$(dig +short -x ${IP}); if [ -z "$HNAME" ]; then HNAME=${IP}; fi; echo ${COUNT} ${HNAME}; done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment